Killing Asynchronous Calls
//instantiate delegate and make call AsyncDelegate dlgt =
IAsyncResult ar = dlgt.BeginInvoke(null,null);
// Poll until call is finished.
while(!ar.IsCompleted){
Application.DoEvents();
}
Thanks in advance
//instantiate delegate and make call AsyncDelegate dlgt =
IAsyncResult ar = dlgt.BeginInvoke(null,null);
// Poll until call is finished.
while(!ar.IsCompleted){
Application.DoEvents();
}
Thanks in advance
If you go down this route and you want to support cancellation on threadpool threads or threads that process multiple items (instead of devoting a new thread to processing exactly one work item), you'll want a latched state variable shared between your watchdog & worker thread to indicate that a block of code should be cancelled, and you'll also want your cancellable code to define when it can and can't be cancelled. This is necessary to scope the cancellation to just the work item that you want to be cancelled.
We do not yet have a complete cancellation mechanism built into the .NET Framework. We have a very good idea about how we want to design it, but we want to make sure we get the cancellation model really correct & integrated with Indigo (Windows Communication Framework) in some manner. We also have System.Transactions with some related functionality. While I even checked in an implementation, it wasn't clear that what we would have been locking ourselves into was the correct model once all these other technologies were fully developed & in use. But you may want to keep an eye out for CancellationRegion & CancellationSignal classes, as well as an ICancelableAsyncResult in future versions.
Brian Grunkemeyer
MS CLR Base Class Library team
I had similar problem. I wanted to send bytes from file to serial port using asynchronous call and allow the user to cancel the sending operation. What I did was I sent the the file in parts (making asynchronous call for every part).
What about throwing an exception until call is finished?