-
Notifications
You must be signed in to change notification settings - Fork 2
/
Program.cs
33 lines (25 loc) · 1.09 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System;
using System.Threading.Tasks;
namespace pubSubEventDelegate{
class Program{
static void Main(string[] args){
// Creating Instance of Publisher
Publisher stackoverflow = new Publisher("StackOverflow.Com", 3000);
Publisher facebook = new Publisher("Facebook.com", 1000);
//Create Instances of Subscribers
Subscriber sub1 = new Subscriber("Florin");
Subscriber sub2 = new Subscriber("Piagio");
Subscriber sub3 = new Subscriber("Shawn");
//Pass the publisher obj to their Subscribe function
sub1.Subscribe(facebook);
sub3.Subscribe(facebook);
sub1.Subscribe(stackoverflow);
sub2.Subscribe(stackoverflow);
//sub1.Unsubscribe(facebook);
//Concurrently running multiple publishers thread
Task task1 = Task.Factory.StartNew(() => facebook.Publish());
Task task2 = Task.Factory.StartNew(() => stackoverflow.Publish());
Task.WaitAll(task1, task2);
}
}
}