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 2 1713
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.co m
"Dave" <dp*@nospam.eli assen.com> wrote in message
news:uv******** ******@TK2MSFTN GP09.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
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.c om> wrote in
message news:%2******** ********@TK2MSF TNGP14.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.co m
"Dave" <dp*@nospam.eli assen.com> wrote in message news:uv******** ******@TK2MSFTN GP09.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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 worker threads. Yes I have gotten it to work,
kind-of - that is I have gotten the shelled processes off of the UI
thread (I think?). But the UI still is not updating properly! Still I
have white boxes for forms, label text that does not update, and...
|
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 to the main thread to be
threadsafe. I want to make this worker class I'm writing a self contained
assembly so that other's can drop it into their projects. My question is:
How can I NOT force those implementing my class to have to call...
|
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 has finished its work. UI stuff is message-queue based and handled
by a single thread spinning the standard message loop. But the worker
thread calling back is obviously a different thread and, of course,
isn't going to be 'serialized' by the...
|
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 unless told to do so by
the onexit event I implemented in the worker object. However there
are the rare circumstance that the thread hits a catastrophic error
and exits the main process loop. So basically the service is now
useless. Is there...
|
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 used WM_USER based messages to
communicate status from the worker thread back to the UI thread. What is
the right way to do this in .Net? Are asynchronous delegates the way to go,
or is there a better (or just different) approach I should...
| |
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 thread is aborted by the system.
How is one to keep the background thread from calling form.Invoke after the
form's window handle has been destroyed? This is definitely happening in my
application. I haven't read anything about this problem in...
|
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 be interrupted to handle an
incoming event (and the flow of execution subsequently diverted to the
respective event handler). My question is at what point or points could
this interruption occur. Will it only occur when the worker thread is...
|
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 me to use MFC.
So I have to use SendMessage(LVM_XXX, hListCtrl) in the worker thread, I
guess.
But I failed, there is nothing displaying in the list control in the UI
|
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 omit this?
I'm dealing with a large number of files with nested includes. There
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |