473,799 Members | 3,072 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1223
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
DirectorySearch er 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************ *************@r eallyidont.com> wrote in
message news:br******** ***********@new s.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
2390
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 thread from another, and I'm almost at the point of acquiescing but curiosity leads me on. Below is a procedure template that I wonder might guarantee behavior during an abort, and I'd like to get some feedback in case it's just plain nonsense.
1
2624
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 the expected behavior for this scenario? Does the thread stay alive until the callback is executed? If an exception is thrown, can it be caught? I posted this message last week, but got no response. I am really hoping someone can help me with...
2
2046
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(...) { ....doing some work Monitor.Enter(Thread_1);
2
1929
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 noticed that some threads, even after resetting the counters, have the old values.
2
4289
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 information: Thread is suspended; attempting to abort. I have a number or threads in my program - some running, some suspended. I hope I don't have to start the thread up again just to abort it??
7
3580
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 request for data only returns the first 25 rows of data. So thas the user knows how many total rows of data there are, a count is returned by another stored procedure. This query can take a while to complete so I have created a delete called...
7
6807
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 period of time. I want something like thread.abort for aborting aynchronous call. Can someone tell me way of aborting asynchronous call.
4
15887
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 gets stuck (I'm working on why that happens) and I want to kill it. I do a thread.abort and the status becomes abortrequested but never actually goes through. If it were an actual process I could kill it but there seems to be no real kill for...
3
1567
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 new Thread(new ThreadStart (git.Go)).Start();
0
9541
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,...
0
10484
Oralloy
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...
0
10251
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 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...
0
10027
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9072
agi2029
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...
1
7565
isladogs
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...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5463
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...
3
2938
bsmnconsultancy
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...

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.