|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Cancel an Asynchronous operation?SQLCommand.BeginExecuteReader, allowing me to loop, checking for user cancellation before the operation has completed, but how then to cancel the SQLCommand if the user wishes to? The "Cancel" method states: ".......... The Cancel method cannot be used to cancel a pending asynchronous operation." The scenario I'm thinking about here concerns a potentially long-running operation the user might start not realising how long it might take, despite a UI warning, then deciding to cancel it. Because I don't know if the operation will take seconds or minutes, I can't set an appropriate timeout other than "0", which means the user must be allowed to cancel it. Is there any way to stop an asynchronous operation "mid-flow" so to speak, without running it on a thread and aborting the thread (not a very clever thing to do)? What about closing the underlying connection or generating an exception, will that stop the pending operation? Robin There is a discrepency in the MSDN documentation.
One of the key ADO.NET team members, Pablo Castro, does recommend using the Cancel command and it does seem to work just fine. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvs05/html/async2.asp Show quoteHide quote "Robinson" <itoldyounottospamme@nowmyinboxisfull.com> wrote in message news:eebr3v$6ng$1$830fa17d@news.demon.co.uk... >I can start an Asynchronous operation against a data source with >SQLCommand.BeginExecuteReader, allowing me to loop, checking for user >cancellation before the operation has completed, but how then to cancel the >SQLCommand if the user wishes to? The "Cancel" method states: > > ".......... The Cancel method cannot be used to cancel a pending > asynchronous operation." > > The scenario I'm thinking about here concerns a potentially long-running > operation the user might start not realising how long it might take, > despite a UI warning, then deciding to cancel it. Because I don't know if > the operation will take seconds or minutes, I can't set an appropriate > timeout other than "0", which means the user must be allowed to cancel it. > Is there any way to stop an asynchronous operation "mid-flow" so to speak, > without running it on a thread and aborting the thread (not a very clever > thing to do)? What about closing the underlying connection or generating > an exception, will that stop the pending operation? > > > Robin > > "Mike McIntyre" <mik***@getdotnetcode.com> wrote in message Ahhhaa. Thats good news. Thanks a million.news:O65Xg4D2GHA.4476@TK2MSFTNGP02.phx.gbl... > There is a discrepency in the MSDN documentation. > > One of the key ADO.NET team members, Pablo Castro, does recommend using > the Cancel command and it does seem to work just fine. > > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvs05/html/async2.asp >
EXE and Dev environment.
Optional Paramter Question Epson TM-T88 Drawer Kick string or StringBuilder return ? Can we Read the text contents from PDF using .net Reflection, creating object with inherited cunstructor, how? Threading using QueueUserWorkItem VB to Delphi Help! Change OpenFileDialog Size (width and height) DataBinding to DataGridView AND TextBoxes? |
|||||||||||||||||||||||