|
-
December 29th, 2008, 09:56 AM
#1
Stopping thread gracefully
I have a thread started using this way, and ThreadFunc keep sending data to a serial port.
Code:
ThreadStart l_startThread = new ThreadStart(ThreadFunc);
Thread myThread = new Thread(l_startThread);
myThread.Start();
public void ThreadFunc()
{
//writing to com port for as long as it wants
}
My problem is how to stop and restart this thread? I can use myThread.Abort(), but i read that this is not a graceful way to stop a thread.
I tried the following :- (but object disposed exception is thrown) or sometimes my pc application just got hanged when i step through the followings.
myThread.Interrupt();
myThread.Join();
I want to be able to stop and restart the thread above (which send data to COM port constinuously, until the user decided to stop the thread.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|