|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
cancelling a backgroundworkerI am using a backgroundworker to execute a lengthy SQL Server stored
procedure. There is no opportunity for the DoWork procedure to test the CancellationPending property, so I can't cancel the operation. What I would like to do instead is terminate the backgroundworker if a cancel button is clicked. Is there a good way to accomplish this? Thanks Bill On 2009-06-24, BillE <bel***@datamti.com> wrote:
> I am using a backgroundworker to execute a lengthy SQL Server stored You would probably need to call CancelAsync and then close the DB Connection -> procedure. > > There is no opportunity for the DoWork procedure to test the > CancellationPending property, so I can't cancel the operation. > > What I would like to do instead is terminate the backgroundworker if a > cancel button is clicked. > > Is there a good way to accomplish this? > to force the code to transition back to managed code. This would most likely cause an sql exception to occure, so, you'll want to make sure your swallowing the exceptions when the CancellationPending property is true... You could probably use an exception filter for that. Just an idea. -- Tom Shelton It could be better to do an async request then rather than using a
backgroundworker : http://www.devx.com/dotnet/Article/26747 (Executing Database Commands Asynchronously with ADO.NET 2.0). -- Show quoteHide quotePatrice "BillE" <bel***@datamti.com> a écrit dans le message de groupe de discussion : uWEfhqP9JHA.***@TK2MSFTNGP05.phx.gbl... > I am using a backgroundworker to execute a lengthy SQL Server stored > procedure. > > There is no opportunity for the DoWork procedure to test the > CancellationPending property, so I can't cancel the operation. > > What I would like to do instead is terminate the backgroundworker if a > cancel button is clicked. > > Is there a good way to accomplish this? > > Thanks > Bill > > Step 1. In the start of your form put "CheckForIllegalCrossThreadCalls = True"
Step 2. Set the "BackGroundWorker.WorkerSupportsCancellation = True" property Step 3. Handle cancelAsync event of the object. -- Show quoteHide quoteRV "Patrice" wrote: > It could be better to do an async request then rather than using a > backgroundworker : > > http://www.devx.com/dotnet/Article/26747 (Executing Database Commands > Asynchronously with ADO.NET 2.0). > > -- > Patrice > > > > > "BillE" <bel***@datamti.com> a crit dans le message de groupe de discussion > : uWEfhqP9JHA.***@TK2MSFTNGP05.phx.gbl... > > I am using a backgroundworker to execute a lengthy SQL Server stored > > procedure. > > > > There is no opportunity for the DoWork procedure to test the > > CancellationPending property, so I can't cancel the operation. > > > > What I would like to do instead is terminate the backgroundworker if a > > cancel button is clicked. > > > > Is there a good way to accomplish this? > > > > Thanks > > Bill > > > > > There is no opportunity for the DoWork procedure to test the
CancellationPending property, so I can't cancel the operation. Thanks Bill Show quoteHide quote "Raja Venkatesh" <RajaVenkat***@discussions.microsoft.com> wrote in message news:76A0ED11-F997-4D2E-B283-D34248B591BB@microsoft.com... > Step 1. In the start of your form put "CheckForIllegalCrossThreadCalls = > True" > Step 2. Set the "BackGroundWorker.WorkerSupportsCancellation = True" > property > Step 3. Handle cancelAsync event of the object. > -- > RV > > > "Patrice" wrote: > >> It could be better to do an async request then rather than using a >> backgroundworker : >> >> http://www.devx.com/dotnet/Article/26747 (Executing Database Commands >> Asynchronously with ADO.NET 2.0). >> >> -- >> Patrice >> >> >> >> >> "BillE" <bel***@datamti.com> a crit dans le message de groupe de >> discussion >> : uWEfhqP9JHA.***@TK2MSFTNGP05.phx.gbl... >> > I am using a backgroundworker to execute a lengthy SQL Server stored >> > procedure. >> > >> > There is no opportunity for the DoWork procedure to test the >> > CancellationPending property, so I can't cancel the operation. >> > >> > What I would like to do instead is terminate the backgroundworker if a >> > cancel button is clicked. >> > >> > Is there a good way to accomplish this? >> > >> > Thanks >> > Bill >> > >> > >> BillE wrote:
> I am using a backgroundworker to execute a lengthy SQL Server stored So, what you're /really/ after is a way to cancel an SQL Server query, like, > procedure. > > There is no opportunity for the DoWork procedure to test the > CancellationPending property, so I can't cancel the operation. > > What I would like to do instead is terminate the backgroundworker if a > cancel button is clicked. > > Is there a good way to accomplish this? ooh, I don't know, SqlCommand.Cancel? Andrew |
|||||||||||||||||||||||