in multithread environment it might be displayed differently… but in a single thread it always iterate the collection of subscribers in order they are subscribed. there is no parallel iteration involved.
Events are multicast delegates and that one has a linked list to store the delegates in. The order of execution is always the same as they are inserted.
Quote:
“An event is nothing but an encapsulated multicast delegate. It can store references to more than one method or event handler. The methods will be executed in the same order as they are added to the event. “
Still not 100% sure but I believe you are write as it is not a multi thread environment:
The invocation list of a delegate is an ordered set of delegates in which each element of the list invokes exactly one of the methods invoked by the delegate. An invocation list can contain duplicate methods. During an invocation, a delegate invokes methods in the order in which they appear in the invocation list. A delegate attempts to invoke every method in its invocation list; duplicates are invoked once for each time they appear in the invocation list. Delegates are immutable; once created, the invocation list of a delegate does not change.
A delegate is either multicast (combinable) or singlecast (noncombinable). Multicast or combinable delegates invoke one or more methods, and can be used in combining operations. Singlecast or noncombinable delegates invoke exactly one method and cannot be used in combining operations. The invocation list of a singlecast delegate A contains a single element: a reference to A.
The answer should be
Yes
Yes
No
yes yes no
what is the argument for the second yes? If i recall correctly the order of events fired are more or less random.
Yes Yes No is correct.
in multithread environment it might be displayed differently… but in a single thread it always iterate the collection of subscribers in order they are subscribed. there is no parallel iteration involved.
No, its Yes No No,
It can happen, that Events in an EventHandler will be executet in different orders, as there were added.
Yes, Yes, No.
Events are multicast delegates and that one has a linked list to store the delegates in. The order of execution is always the same as they are inserted.
Quote:
“An event is nothing but an encapsulated multicast delegate. It can store references to more than one method or event handler. The methods will be executed in the same order as they are added to the event. “
Still not 100% sure but I believe you are write as it is not a multi thread environment:
The invocation list of a delegate is an ordered set of delegates in which each element of the list invokes exactly one of the methods invoked by the delegate. An invocation list can contain duplicate methods. During an invocation, a delegate invokes methods in the order in which they appear in the invocation list. A delegate attempts to invoke every method in its invocation list; duplicates are invoked once for each time they appear in the invocation list. Delegates are immutable; once created, the invocation list of a delegate does not change.
A delegate is either multicast (combinable) or singlecast (noncombinable). Multicast or combinable delegates invoke one or more methods, and can be used in combining operations. Singlecast or noncombinable delegates invoke exactly one method and cannot be used in combining operations. The invocation list of a singlecast delegate A contains a single element: a reference to A.
https://msdn.microsoft.com/fi-FI/library/windows/apps/system.delegate(v=vs.71)
YES YES NO.
TESTED.
public class Alert
{
public 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();
}
static void Main(string[] args)
{
Subscriber subscriber = new Subscriber();
subscriber.Subscribe();
subscriber.Execute();
Console.ReadKey();
}
}
y y n