From: Harlan Messinger on
Frank Uray wrote:
> "Bjørn Brox" wrote:
>
>> Frank Uray skrev:
>>> Hi all
>>>
>>> I have some trouble with threading:
>>> I have a control thread which it is starting another
>>> thread. This thread is executing some long run SQL statements.
>>> The control thread is looping and checking for a cancel flag
>>> which the user can set to cancel all.
>>>
>>> In the control thread, I tried to abort the other thread,
>>> but no reaction ...
>>> Can somebody tell me how to kill a thread which is busy ?
>>>
>>> Thanks and best regards
>>> Frank Uray
>>>
>> Killing hard and brutally a thread which are executing "long run SQL
>> statements" does not sound like a good idea, unless it it just queries.
>>
>> The SQL thread should it selves check
>>
>> --
>> Bjørn Brox
>> .
>>
> Hi Bjørn
>
> Well, sometimes it is necessary to do that,
> like in SQL Management Studio.

In my experience, if you click Cancel during a very long query in SSMS,
it still takes a very long time before it ends the operation.
From: Harlan Messinger on
Frank Uray wrote:
> "Bjørn Brox" wrote:
>
>> Frank Uray skrev:
>>> Hi all
>>>
>>> I have some trouble with threading:
>>> I have a control thread which it is starting another
>>> thread. This thread is executing some long run SQL statements.
>>> The control thread is looping and checking for a cancel flag
>>> which the user can set to cancel all.
>>>
>>> In the control thread, I tried to abort the other thread,
>>> but no reaction ...
>>> Can somebody tell me how to kill a thread which is busy ?
>>>
>>> Thanks and best regards
>>> Frank Uray
>>>
>> Killing hard and brutally a thread which are executing "long run SQL
>> statements" does not sound like a good idea, unless it it just queries.
>>
>> The SQL thread should it selves check
>>
>> --
>> Bjørn Brox
>> .
>>
> Hi Bjørn
>
> Well, sometimes it is necessary to do that,
> like in SQL Management Studio.

In my experience, if you click Cancel during a very long query in SSMS,
it still takes a very long time before it ends the operation.
From: Frank Uray on
Hi Harlan

Thanks for your replay.
Depending on the query (inserts, updates),
yes it takes a long time to cancel, and in this case the delay is ok.
My querys are procedures with very small inserts and updates
and without transactions, they stop immediately.

Regards
Frank Uray



"Harlan Messinger" wrote:

> Frank Uray wrote:
> > "Bjørn Brox" wrote:
> >
> >> Frank Uray skrev:
> >>> Hi all
> >>>
> >>> I have some trouble with threading:
> >>> I have a control thread which it is starting another
> >>> thread. This thread is executing some long run SQL statements.
> >>> The control thread is looping and checking for a cancel flag
> >>> which the user can set to cancel all.
> >>>
> >>> In the control thread, I tried to abort the other thread,
> >>> but no reaction ...
> >>> Can somebody tell me how to kill a thread which is busy ?
> >>>
> >>> Thanks and best regards
> >>> Frank Uray
> >>>
> >> Killing hard and brutally a thread which are executing "long run SQL
> >> statements" does not sound like a good idea, unless it it just queries.
> >>
> >> The SQL thread should it selves check
> >>
> >> --
> >> Bjørn Brox
> >> .
> >>
> > Hi Bjørn
> >
> > Well, sometimes it is necessary to do that,
> > like in SQL Management Studio.
>
> In my experience, if you click Cancel during a very long query in SSMS,
> it still takes a very long time before it ends the operation.
> .
>
From: Peter Duniho on
Frank Uray wrote:
> Hi Peter
>
> Thanks for your answer.
>
> Well, I know it is better to give the thread a signal to cancel,
> but when it is busy like when running SQL Statement, there is
> now way ...

Yes, that's correct. You simply have to wait for the SQL operation to
complete in order to do anything with that thread.

The rest of your code can, of course, just ignore the thread and any
possible results after some specific timeout. But the thread itself
will have to remain until SQL gives up or completes.

(Of course, there is always an underlying OS thread in which the SQL
stuff is executing, and of course the OS does allow one to forcefully
terminate a thread. But that's not something that'd generally be a good
idea in any case, and it's definitely not something you want to do in a
managed application).

Pete
First  |  Prev  | 
Pages: 1 2
Prev: Image size mystery
Next: Web Setup Project failure