Indeed: Y, N, N:
Also note that the constuctor is executed twice, by new and explicit.
Output will be something like:
First
Second
Third
Third
First
Second
Third
Third,
3
1
khoa_chung_89says:
Agree Y,N,N.
Don’t care how much time the constructor is called. The Subscribe() method is just called one time. So it cannot output like you said. It just st like:
First
Second
Third
Third
3
0
JS1985says:
Wow.. the Main method is located within the Subscriber class.
Is that intended?
0
0
Pascalsays:
Yes YES NO, Tested in VS, it follows an ordering, i cant subscribe first and second person gets his response before me
3
2
migsays:
it was in your case but you can’t “always” rely on it
1
0
migsays:
https://msdn.microsoft.com/en-us/library/mt299485(v=nav.90).aspx
“There can be multiple subscribers to the same event from various locations in the application code. When an event is raised, the subscriber functions are run one at a time in random order.”
3
0
z1ppzsays:
YES YES NO
public class Alert
{
public event EventHandler SendMessage;
public void Execute()
{
SendMessage(this, new EventArgs());
}
}
public class Subscriber
{
Alert alert = new Alert();
yes
yes
no
4
3
Agree with you
0
4
yes
no https://stackoverflow.com/questions/374398/are-event-subscribers-called-in-order-of-subscription
no
10
1
Indeed: Y, N, N:
Also note that the constuctor is executed twice, by new and explicit.
Output will be something like:
First
Second
Third
Third
First
Second
Third
Third,
3
1
Agree Y,N,N.
Don’t care how much time the constructor is called. The Subscribe() method is just called one time. So it cannot output like you said. It just st like:
First
Second
Third
Third
3
0
Wow.. the Main method is located within the Subscriber class.
Is that intended?
0
0
Yes YES NO, Tested in VS, it follows an ordering, i cant subscribe first and second person gets his response before me
3
2
it was in your case but you can’t “always” rely on it
1
0
https://msdn.microsoft.com/en-us/library/mt299485(v=nav.90).aspx
“There can be multiple subscribers to the same event from various locations in the application code. When an event is raised, the subscriber functions are run one at a time in random order.”
3
0
YES YES NO
public class Alert
{
public event EventHandler SendMessage;
public void Execute()
{
SendMessage(this, new EventArgs());
}
}
public class Subscriber
{
Alert alert = new Alert();
public void Subscribe()
{
alert.SendMessage += (sender, e) => { Console.WriteLine(“First”); };
alert.SendMessage += (sender, e) => { Console.WriteLine(“Second”); };
alert.SendMessage += (sender, e) => { Console.WriteLine(“Third”); };
alert.SendMessage += (sender, e) => { Console.WriteLine(“Third”); };
}
public void Execute()
{
alert.Execute();
}
public static void Main()
{
Subscriber subscriber = new Subscriber();
subscriber.Subscribe();
subscriber.Execute();
Console.ReadKey();
}
}
1
2
Yes Yes No
Out pot is
—————-
First
Second
Third
Third
1
2