Asynchronous threading question

  • Thread starter Thread starter Pug Fugly
  • Start date Start date
P

Pug Fugly

I have a function that takes in a parameter, and in the function it
calls the .BeginInvoke on the worker delegate. I know that the
System.AsyncCallback callback function takes in IAsyncResult as the
only parameter. But I have a case where I need to pass a parameter
from the function that calls the .BeginInvoke to my callback that
calls the .EndInvoke. Is this possible? Can I add another parameter
to my callback function, or is IAsyncResult the only parameter allowed
for the callback delegate?

Thanks,
Slavisa
 
Pug said:
I have a function that takes in a parameter, and in the function it
calls the .BeginInvoke on the worker delegate. I know that the
System.AsyncCallback callback function takes in IAsyncResult as the
only parameter. But I have a case where I need to pass a parameter
from the function that calls the .BeginInvoke to my callback that
calls the .EndInvoke. Is this possible? Can I add another parameter
to my callback function, or is IAsyncResult the only parameter allowed
for the callback delegate?

Yes, it is the only parameter allowed, but you can use the AsyncState member
of the IAsyncResult interface to pass custom data. It's the third parameter
in the compiler-generated BeginInvoke method for your delegate.
 
Back
Top