473,666 Members | 2,538 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Aborting a thread ?

Hello.
I want to abort a thread whose thread function contains something like :
void threadfunc ()
{
while ( 1 )
{
... some code
udpClient.Recei ve(...); // instance to read network
data
... some code using received data
}
}

Another method in my thread class has :
thread.Abort();

Problem when Abort() has been called : the thread, as seen in debug mode
shows :
1. do NOT abort
2. remains in an AbortRequested ThreadState
3. IsAlive is true

Question :
Does someone can tell me what can maintains a thread in an
AbortRequested ThreadState ?

Thank you.
jmd
Jan 5 '06 #1
3 5947

"jmd.msdn" <jm******@newsg roup.nospam> wrote in message
news:eJ******** ******@TK2MSFTN GP09.phx.gbl...
Hello.
I want to abort a thread whose thread function contains something like :
void threadfunc ()
{
while ( 1 )
{
... some code
udpClient.Recei ve(...); // instance to read network
data
... some code using received data
}
}

Another method in my thread class has :
thread.Abort();

Problem when Abort() has been called : the thread, as seen in debug mode
shows :
1. do NOT abort
2. remains in an AbortRequested ThreadState
3. IsAlive is true

Question :
Does someone can tell me what can maintains a thread in an
AbortRequested ThreadState ?

Thank you.
jmd


1. Never call Thread.Abort, this method is only safe when you intend to
abandon the current Application domain, in which case it's not needed to
call Abort anyway because AppDomain.Unloa d calls Abort when it uloads the
offending domain.
2. When you need to end a thread function you should set an event or set a
status flag that you can check in your while loop.

But this won't solve your problem as it's related to the Receive call which
is suspended (waiting for data) in unmanaged code, all you can do is close
udpClient's underlying socket, this will force the Receive to end and give
you a chance to exit the loop.

Willy.

Jan 5 '06 #2
Thank you very much gor your speedy response.
Yes, as you say, I usually stop a thread with a flag and a while ( !
stopwork ) loop.
This one was to test the receive udpclient method.
I will follow your suggestion tomorrow to stop the thread with :
udpclient.Clien t.Close()

jean-marie

"Willy Denoyette [MVP]" <wi************ *@telenet.be> wrote in message
news:e$******** ******@tk2msftn gp13.phx.gbl...

"jmd.msdn" <jm******@newsg roup.nospam> wrote in message
news:eJ******** ******@TK2MSFTN GP09.phx.gbl...
Hello.
I want to abort a thread whose thread function contains something like :
void threadfunc ()
{
while ( 1 )
{
... some code
udpClient.Recei ve(...); // instance to read network
data
... some code using received data
}
}

Another method in my thread class has :
thread.Abort();

Problem when Abort() has been called : the thread, as seen in debug mode
shows :
1. do NOT abort
2. remains in an AbortRequested ThreadState
3. IsAlive is true

Question :
Does someone can tell me what can maintains a thread in an
AbortRequested ThreadState ?

Thank you.
jmd


1. Never call Thread.Abort, this method is only safe when you intend to
abandon the current Application domain, in which case it's not needed to
call Abort anyway because AppDomain.Unloa d calls Abort when it uloads the
offending domain.
2. When you need to end a thread function you should set an event or set a
status flag that you can check in your while loop.

But this won't solve your problem as it's related to the Receive call
which is suspended (waiting for data) in unmanaged code, all you can do is
close udpClient's underlying socket, this will force the Receive to end
and give you a chance to exit the loop.

Willy.

Jan 6 '06 #3
Try closing your client before calling thread abort in the thread where
you are calling Abort
jmd.msdn wrote:
Hello.
I want to abort a thread whose thread function contains something like :
void threadfunc ()
{
while ( 1 )
{
... some code
udpClient.Recei ve(...); // instance to read network
data
... some code using received data
}
}

Another method in my thread class has :
thread.Abort();

Problem when Abort() has been called : the thread, as seen in debug mode
shows :
1. do NOT abort
2. remains in an AbortRequested ThreadState
3. IsAlive is true

Question :
Does someone can tell me what can maintains a thread in an
AbortRequested ThreadState ?

Thank you.
jmd

Jan 6 '06 #4

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

Similar topics

1
2615
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
2034
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);
3
2031
by: Jeff Greenland | last post by:
Hello everyone, I am having problems with Timers in a web application. They just seem to stop running after 15 minutes or so. My web application is set up like this: When a user hits a page in the site, that page (.aspx) instantiates a compiled class (.DLL). The instantiation process creates a Timer that runs in the background to perform tasks every so often (such as notifying clients
2
4283
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
6800
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.
0
2462
by: =?Utf-8?B?aGVyYmVydA==?= | last post by:
I read from a serialport using a worker thread. Because the worker thread t does not loop often, I cannot wait to terminate the worker thread using a boolean in the While condition. So I have a StopReader() method that simply aborts the worker thread (is there a better way for the above situation?). The StopReader creates an ObjectDisposedException when calling t.Abort(). WHY? Public Sub StopReader()
4
15879
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
1557
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();
7
3260
by: matthewaveryusa | last post by:
I have been reading a lot about aborting threads and there seems to be something missing to do this easily on program exit. This is what I want to do but I will need some help. I declared a global boolean called KillAllThreads (public static bool in abstact class). I initialize it to false in my main program before my main window opens. I then have some threads open and close. I keep count of opened and closed threads by using another...
0
8883
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
8787
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
8645
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...
1
6203
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
5672
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
4200
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...
1
2776
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2013
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1778
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.