Can terminating an ADO worker thread cause a leak?

  • Thread starter Thread starter Dave
  • Start date Start date
D

Dave

I have an application that queries SQL Server and Index Server using ADO.
I'd like to have a feature where a user can cancel a long-running query.
What I plan on doing is to move my query code to a worker thread which will
then post a message back to the main thread when it's done. Then, the
application can have a button that a user can press to terminate the worker
thread. That way, the app stays responsive during a long-running query. Is
there an easier way to do this that anyone would suggest?

Assuming that that's the way I go - can anyone tell me if the framework will
clean up properly if I terminate a thread in the middle of executing an ADO
query? I'm wondering if this could cause any leaks.

- Dave
 
Dave,

Do you mean ADO.NET or ADO classic? Either way, there are calls through
COM interop and calls through the P/Invoke layer which can not be
terminated. Yes, you can make the calls on another thread, but if the
thread is in the middle of a call to an unmanaged piece of code, then the
call to Abort will block.

I think that the better thing to do would be to close the connection
from another thread, and then swallow any exception that is thrown in the
worker thread as a result. This should work, and the thread should
terminate nicely.

Hope this helps.
 
I'm using ADO.NET and querying index server through IXSSO.

I tried what you suggested, and it works for ADO.NET. But, I can't see a
way to do the analogous thing to closing an ADO connection, with IXSSO.

What about calling Abort() on the worker thread? This causes an exception
to be throw in the worker thread, and seems to terminate the IXSSO query ok.

- Dave

Nicholas Paldino said:
Dave,

Do you mean ADO.NET or ADO classic? Either way, there are calls through
COM interop and calls through the P/Invoke layer which can not be
terminated. Yes, you can make the calls on another thread, but if the
thread is in the middle of a call to an unmanaged piece of code, then the
call to Abort will block.

I think that the better thing to do would be to close the connection
from another thread, and then swallow any exception that is thrown in the
worker thread as a result. This should work, and the thread should
terminate nicely.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


Dave said:
I have an application that queries SQL Server and Index Server using ADO.
I'd like to have a feature where a user can cancel a long-running query.
What I plan on doing is to move my query code to a worker thread which
will
then post a message back to the main thread when it's done. Then, the
application can have a button that a user can press to terminate the
worker
thread. That way, the app stays responsive during a long-running query.
Is
there an easier way to do this that anyone would suggest?

Assuming that that's the way I go - can anyone tell me if the framework
will
clean up properly if I terminate a thread in the middle of executing an
ADO
query? I'm wondering if this could cause any leaks.

- Dave
 
Back
Top