473,395 Members | 1,348 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Can terminating an ADO worker thread cause a leak?

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
Nov 16 '05 #1
2 1681
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]
- mv*@spam.guard.caspershouse.com
"Dave" <dp*@nospam.eliassen.com> wrote in message
news:uv**************@TK2MSFTNGP09.phx.gbl...
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

Nov 16 '05 #2
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 [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:%2****************@TK2MSFTNGP14.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com
"Dave" <dp*@nospam.eliassen.com> wrote in message
news:uv**************@TK2MSFTNGP09.phx.gbl...
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


Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Joey Powell | last post by:
Re: Original post = Windows forms - how do I get them to render/update properly? from August 22. Okay I am making some progress with being able to use delegates to run my shelled processes on...
3
by: Jacob | last post by:
I'm working on a class that needs to be called from a windows form, do it's work, and then, show progress back to the main form. I'm well aware that worker threads need to call Invoke for updates...
8
by: emma middlebrook | last post by:
Hi My main UI thread needs to create a worker thread. To signal that the work is finished the UI should be updated. I'm worried about that worker thread calling back via a delegate when it...
2
by: T Conti | last post by:
Hello: I created a basic windows service that polls a db and sends emails to our subscribers. In the onstart method I create a new thread and send it on its way to do work. It should never end...
7
by: Brett Robichaud | last post by:
I'm trying to decide on the right approach for communication between the UI and a worker thread in a WinForms app. I am very familiar with threads in the unmanaged C++ world and in the past have...
5
by: Stephen Lamb | last post by:
I have a background worker thread which I start from a form's HandleCreated event that makes calls back to the form using Invoke. During shutdown the form is disposed and the background worker...
5
by: Bill Davidson | last post by:
Hello All: I've got a question about synchronization requiremements in a C# worker thread procedure that, among other things, sinks events from outside sources. I realize the worker thread will...
3
by: zhaoyandong | last post by:
I have two threads, one UI thread, the other, the worker thread, which is responsible for keeping on search things and post the found results to a list control on the UI. My leader doesn't allow...
8
by: Lauren the Ravishing | last post by:
Hi, In ASP, is it absolutely necessary to set an object to Nothing after being used? set myObj = server.createObject("myDLL.myClass") call myObj.useClass set myObj = Nothing <--- can I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.