Reputation: 132
If I use the following code:
public List<int> _SomeList = new List<int>();
public event EventHandler<SomeEventArgs> SomeEvent;
public int StartEvent
{
get
{
return _SomeList[_SomeList.Count - 1];
}
set
{
lock (_SomeList)
{
_SomeList.Add(value);
SomeEvent?.Invoke(this, new SomeEventArgs());
}
}
}
Is it made sure that only after all delegate calls are finished it resumes on the point where it was (where the Invoke happens?), or is it like overran, like if the Invoke is made, the calls for the delegates are made in the background and the program continues immediatly?
Upvotes: 2
Views: 61
Reputation: 11889
SomeEvent?.Invoke(this, new SomeEventArgs());
is basically the same as:
if(SomeEvent != null)
{
SomeEvent(this, new SomeEventArgs());
}
So, the answer is, no, SomeEvent
will not run in a different thread or anything else, it will call the event in the same way as if you were calling a simple function. Bear in mind rhe order of delegates will be unknown (if more than one has been registered).
Upvotes: 3