473,321 Members | 1,748 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,321 software developers and data experts.

Question about aborting a thread.

Hi there,

I have a "worker thread", which can perform one of many tasks, including
fetching and sending data blobs to a database, load files etc. Now, a
progress dialog is displayed while the thread is performing these actions
with a "cancel" button on it. My question is, at what point does the thread
actually stop running after I have executed "Abort" in response to the user
pressing cancel? Is it immediate? Or does the thread continue processing
until a convienient moment is found to stop it running? In theory, if I
have, say, 100 transactions to perform, I would like the thread to abort on
completion of any single transaction (atomic) - here by transaction I mean,
for example: {loading a file, processing the file, adding it to the
database}. I don't like the idea of having a boolean flag inside the thread
loop (m_bCancelling for example), because the calling thread will not be
able to execute until the current one is cancelled. The caller cannot block
however waiting for it to finish before kicking off the new operation,
because the thread itself uses Invoke on the caller to execute events! (ie.
deadlock). Any ideas? (was I obtuse enough!??)

Thanks

Robin
Nov 20 '05 #1
1 1209
According to the docs, it aborts at a "safe place" (I'm still not 100% sure
what that means!). however, it will not abort it while it is in native code
(so P/Invoke or anywhere that it calls into native code itself).

I had a very unintended change to my thread aborts when I was doing some
work to get rid of a com interop assembly. I was using GetObject on a type
of IAdsUser (which required the com interop assembly). I moved to using the
DirectorySearcher for more of the work. Previously, my threads would abort
approximately immediately. Now, they wait for their operation to finish (I
guess because the directory searcher isn't a "safe" abort location?).

Jerry

"Robin Tucker" <id*************************@reallyidont.com> wrote in
message news:br*******************@news.demon.co.uk...
Hi there,

I have a "worker thread", which can perform one of many tasks, including
fetching and sending data blobs to a database, load files etc. Now, a
progress dialog is displayed while the thread is performing these actions
with a "cancel" button on it. My question is, at what point does the thread actually stop running after I have executed "Abort" in response to the user pressing cancel? Is it immediate? Or does the thread continue processing
until a convienient moment is found to stop it running? In theory, if I
have, say, 100 transactions to perform, I would like the thread to abort on completion of any single transaction (atomic) - here by transaction I mean, for example: {loading a file, processing the file, adding it to the
database}. I don't like the idea of having a boolean flag inside the thread loop (m_bCancelling for example), because the calling thread will not be
able to execute until the current one is cancelled. The caller cannot block however waiting for it to finish before kicking off the new operation,
because the thread itself uses Invoke on the caller to execute events! (ie. deadlock). Any ideas? (was I obtuse enough!??)

Thanks

Robin

Nov 20 '05 #2

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

Similar topics

2
by: cottonviking | last post by:
Greetings, all! I've been pondering the pitfalls of aborting a secondary thread in a service app I'm writing (VB, fx v1.1). Everything I've read so far pretty much dissuades one from aborting one...
1
by: johnny | last post by:
In a multi-threaded application, say a worker thread makes an asynchronous call and specifies a callback method. But before the callback is executed, the thread is aborted by its creator. What is...
2
by: Xarky | last post by:
Hi, I am writing a small program, that makes use of threads. Now in on of the threads I have a critical section, where I am using the Monitor to handle this. *** Thread_1 *** started for(...)...
2
by: Naveen Mukkelli | last post by:
Hi, I'm working on a multi-threaded application. I'm using ThreadPools. One of the requirements of the application is, if certain exception occurs all the counters have to be reset. I have...
2
by: Mark Denardo | last post by:
I'm trying to abort a suspended thread, but I get a ThreadStateException: An unhandled exception of type 'System.Threading.ThreadStateException' occurred in mscorlib.dll Additional...
7
by: Susan | last post by:
In the application I am working on, the user makes a request of information from the database. As there is a great deal of information to go through and possibly return, to speed things up, the...
7
by: archana | last post by:
Hi all, I am having application in which i am doing asynchronous call.I am using manualresetevent to wait for asynchronous call to complete. I want to stop asynchronous call after certain...
4
by: Mufasa | last post by:
Is there any way to force a thread to abort and really have it abort? I have a thread that every once in a while gets hung to so I kill it. Problem is I have a thread that every once in a while...
3
by: AdrianDev | last post by:
Hi, I have a thread which I call like this: // Allocate a new thread containing class with the host getInfoThread git = new getInfoThread(host); // Create the thread and call the Go method...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.