None,
I would create a delegate like you are, then call the BeginInvoke method
on the delegate. It will return an implementation of IAsyncResult to you.
Once you have that, you can call the WaitOne method on the WaitHandle
returned by the AsyncWaitHandle property.
This would require you to have a blocking version of DoAsyncStuff
basically. You don't have to worry about the threading, since the
delegate's implementation of BeginInvoke will handle that for you.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
None said:
I guess this would work. Is there a simpler way?
public delegate void MyCallbackDelegate(int data);
public class MyWebService : System.Web.Services.WebServices
{
public void MyMethod()
{
CallbackWrapper callbackWrapper = new CallbackWrapper();
DoAsyncStuff(new MyCallbackDelegate(callbackWrapper.Callback));
callbackWrapper.WaitForCallback();
}
}
public class CallbackWrapper()
{
bool done = false;
int myInt;
public void Callback(int data)
{
myInt = data;
done = true;
}
public void WaitForCallback()
{
while (done == false); // Can add timeout logic as well
}
}