force kill thread

  • Thread starter Thread starter Frank Uray
  • Start date Start date
F

Frank Uray

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
 
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 ...

Thanks anyway, Frank
 
Hi Bjørn

Well, sometimes it is necessary to do that,
like in SQL Management Studio.

Regards
Frank Uray
 
Frank said:
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.
 
Frank said:
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.
 
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
 
Frank said:
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
 
Back
Top