Home All Groups Group Topic Archive Search About

cancelling a backgroundworker

Author
24 Jun 2009 6:36 PM
BillE
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

Author
24 Jun 2009 11:31 PM
Tom Shelton
On 2009-06-24, BillE <bel***@datamti.com> wrote:
> 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?
>

You would probably need to call CancelAsync and then close the DB Connection -
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
Are all your drivers up to date? click for free checkup

Author
25 Jun 2009 8:32 AM
Patrice
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




Show quoteHide quote
"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
>
>
Author
27 Jun 2009 5:00 PM
Raja Venkatesh
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


Show quoteHide quote
"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
> >
> >
>
Author
30 Jun 2009 12:50 PM
BillE
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
>> >
>> >
>>
Author
1 Jul 2009 9:23 AM
Andrew Morton
BillE wrote:
> 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?

So, what you're /really/ after is a way to cancel an SQL Server query, like,
ooh, I don't know, SqlCommand.Cancel?

Andrew

Bookmark and Share