Stopping a thread "during" a statement

  • Thread starter Thread starter Oliver J. Hanau
  • Start date Start date
O

Oliver J. Hanau

I need to call a time-consuming stored procedure on an SQL Server. This
means that a single SqlCommand.ExecuteNonQuery() call might take a
couple of hours. That's why I put it into a subthread, so I can at
least show the clock running.

I would very much like to allow the user to stop this operation, but
calling Thread.Abort() only sets the ThreadState to AbortRequested.
Only when the ExecuteNonQuery() call then returns, a
ThreadAbortException is finally encountered, but this could happen a
couple of hours after clicking "Cancel", so it's not what I need.

When I debug this in VS 2005, it considers the application to be
running because of this thread until I press "Stop Debugging",
whereupon the thread is stopped immediately. So, VS 2005 is able to
terminate this process during the call. Does it do this via WinAPI
calls the way the Task Manager would (I assume), or is there a less
messy way in .NET?

Thanks
Oliver
 
Oliver said:
I need to call a time-consuming stored procedure on an SQL Server. This
means that a single SqlCommand.ExecuteNonQuery() call might take a
couple of hours. That's why I put it into a subthread, so I can at
least show the clock running.

I would very much like to allow the user to stop this operation, but
calling Thread.Abort() only sets the ThreadState to AbortRequested.
Only when the ExecuteNonQuery() call then returns, a
ThreadAbortException is finally encountered, but this could happen a
couple of hours after clicking "Cancel", so it's not what I need.

SqlCommand.Cancel any use here?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top