K
K
kot25662021-11-07 14:19:30
C++ / C#
kot2566, 2021-11-07 14:19:30

What happens under the hood when I call MyEvent?.Invoke, MyEvent.BeginInvoke?

What happens under the hood when I call MyEvent?.Invoke(), MyEvent.BeginInvoke() on an event in c#?
What threads are running on?
What does it have to do with Dispatcher.Invoke(), Dispatcher.BeginInvoke(). This answer

is not clear enough, that 's why I'm asking. Did I understand correctly: With MyEvent?.Invoke() , execution stops until all bound event handlers have been executed. When MyEvent?.BeginInvoke() does not stop execution, do several ThreadPool threads run in parallel for each attached handler?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2021-11-08
@vabka

I think this answer is good enough:
https://stackoverflow.com/questions/1916095/how-do...
Yes. A thread will be taken from the thread pool, but do not forget to call EndInvoke, otherwise the thread will not return to the pool.
In general, it's better to use Rx instead of events: https://github.com/dotnet/reactive
If this is done in the UI, then there is also an add-on on top of it: https://github.com/reactiveui/ReactiveUI

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question