Re: Status on synchronous call
"Inbar, Ron" <[email protected]>
| Newsgroups | gmane.comp.windows.devel.dotnet.advanced |
|---|---|
| Message-ID | <BE931D64DE776F4B8416705E4586D4902D4566BDC9@NLCLUEXM02.connect1.local> |
Hi Paul,
Try this:
public class ThirdPartyClass
{
// For simplicity, I'm assuming the method has no input or output and that it's static.
public static void ThirdPartyMethod();
}
class YourClass
{
delegate void ThirdPartyMethodDelegate();
static void Main(string[] args)
{
ThirdPartyMethodDelegate d = new ThirdPartyMethodDelegate(ThirdPartyClass.ThirdPartyMethod);
IAsyncResult asyncCall = d.BeginInvoke(null, null);
try
{
while (!asyncCall.IsCompleted)
{
Console.WriteLine("Still working...");
// Wait at most 500 milliseconds for the call to complete, then check for completion again.
asyncCall.AsyncWaitHandle.WaitOne(500);
}
Console.WriteLine("Done!");
}
finally
{
d.EndInvoke(asyncCall);
}
}
}
Also see my article http://www.codeproject.com/KB/architecture/asyncgen.aspx, especially this paragraph: http://www.codeproject.com/KB/architecture/asyncgen.aspx#SynchronousInvocation15.
Regards,
Ron Inbar
The information contained in this message may be confidential and legally protected under applicable law. The message is intended solely for the addressee(s). If you are not the intended recipient, you are hereby notified that any use, forwarding, dissemination, or reproduction of this message is strictly prohibited and may be unlawful. If you are not the intended recipient, please contact the sender by return e-mail and destroy all copies of the original message.
===================================
View archives and manage your subscription(s) at http://peach.ease.lsoft.com/archives