Asynchronous Delegates

T

Tobias Matzat

Hi!

Is it possible to wait for the callback method to finish? When using a
WaitHandle only the call of EndInvoke is awaited. I would like to do
some calculations in the callback-method. But I don't know how to inform
the main thread that the calculations are done, besides defining an
event. Is it not possible to let the callback method do the work? Or am
I getting something wrong?

THX!
Tobias
 
N

Nicholas Paldino [.NET/C# MVP]

Tobias,

You should let the callback method do your work. This will be on a
thread other than the main thread that the BeginInvoke was called on.

If you need to notify your main thread (which I assume is your UI
thread), then create a method that will serve as a callback for a delegate
you define. Then, in your callback method, when the calcs are done, call
the Invoke method on the form/control on the UI thread, passing a delegate
that wraps the method to be called.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top