asynchonous callbacks

  • Thread starter Thread starter Paul
  • Start date Start date
P

Paul

What is the best way to return to the calling code when calling a
asynchronous i/o call in C#. I have in other situations written
systems that were totally event driven so the callback fires an event.
My initial C# attempt has involved the callback re-calling the
origination function with a parameter object representing the modified
state i.e. call success and the next operation to perform. However I
am not sure what this is doing to the call-stack.
Is the method I am using correct?
Should I fire an event in the callback, delegated to calling function.
Should I block the calling function using a synchronising mechanism?
(How?)
 
If you must "return to the calling code", then your last option (blocking
when your result is required) is probably the best. (I'm kind of guessing
here, since I don't really know for sure what you're trying to accomplish)

To do this look at Asynchronous Delegates and usage of the
AsyncResult/IAsyncResult types. You can start your long process, continue to
do operations, then when you need the result you can block until it is ready
(if it isn't already there).

http://msdn.microsoft.com/library/d...s/cpguide/html/cpovrasynchronousdelegates.asp
 
Back
Top