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

How to stop a blocked worker thread?

Ole
CF2.0
VS2005
C#

How to stop a worker thread that is e.g. listening for data on a port when
the application is closed?

Thanks,
Ole
May 29 '06 #1
5 2780
1. Make it a Background thread (set the IsBackground proeprty)
2. Use timeouts in your wait that periodically come back to see if it should
end
3. Wait on multiple items, like data receive and a quit event

-Chris

"Ole" <ol*@blabla.com> wrote in message
news:Oo**************@TK2MSFTNGP04.phx.gbl...
CF2.0
VS2005
C#

How to stop a worker thread that is e.g. listening for data on a port when
the application is closed?

Thanks,
Ole

May 29 '06 #2
AC

Chirs' suggestion 1 should be used carefully as it might still
block the process from exit, if there's a blocking call into
native code going on.

In your particular case where you're listening to data on a port,
I'd recommend Close/Dispose the socket from your main thread,
which will give an ObjectDisposedException in the background
thread that you should handle gracefully.
"<ctacke/>" <ctacke_AT_OpenNETCF_com> wrote in message news:O3**************@TK2MSFTNGP05.phx.gbl...
1. Make it a Background thread (set the IsBackground proeprty)
2. Use timeouts in your wait that periodically come back to see if it should end
3. Wait on multiple items, like data receive and a quit event

-Chris

"Ole" <ol*@blabla.com> wrote in message news:Oo**************@TK2MSFTNGP04.phx.gbl...
CF2.0
VS2005
C#

How to stop a worker thread that is e.g. listening for data on a port when the application is closed?

Thanks,
Ole


May 29 '06 #3
Ole
The "socket.Receive" method doesn't include a time out parameter so are
there another ways to do it?

Thanks
Ole

"<ctacke/>" <ctacke_AT_OpenNETCF_com> wrote in message
news:O3**************@TK2MSFTNGP05.phx.gbl...
1. Make it a Background thread (set the IsBackground proeprty)
2. Use timeouts in your wait that periodically come back to see if it
should end
3. Wait on multiple items, like data receive and a quit event

-Chris

"Ole" <ol*@blabla.com> wrote in message
news:Oo**************@TK2MSFTNGP04.phx.gbl...
CF2.0
VS2005
C#

How to stop a worker thread that is e.g. listening for data on a port
when the application is closed?

Thanks,
Ole


May 29 '06 #4
Use BeginReceive, which you can stop when the app closes by calling Close on
the socket.

-Chris
"Ole" <ol*@blabla.com> wrote in message
news:ev**************@TK2MSFTNGP04.phx.gbl...
The "socket.Receive" method doesn't include a time out parameter so are
there another ways to do it?

Thanks
Ole

"<ctacke/>" <ctacke_AT_OpenNETCF_com> wrote in message
news:O3**************@TK2MSFTNGP05.phx.gbl...
1. Make it a Background thread (set the IsBackground proeprty)
2. Use timeouts in your wait that periodically come back to see if it
should end
3. Wait on multiple items, like data receive and a quit event

-Chris

"Ole" <ol*@blabla.com> wrote in message
news:Oo**************@TK2MSFTNGP04.phx.gbl...
CF2.0
VS2005
C#

How to stop a worker thread that is e.g. listening for data on a port
when the application is closed?

Thanks,
Ole



May 29 '06 #5
Ole
Just setting it to be a backgroundthread seems to work - the app closes
without having to do anything else.

Thanks a lot
Ole
"<ctacke/>" <ctacke_AT_OpenNETCF_com> wrote in message
news:O1**************@TK2MSFTNGP02.phx.gbl...
Use BeginReceive, which you can stop when the app closes by calling Close
on the socket.

-Chris
"Ole" <ol*@blabla.com> wrote in message
news:ev**************@TK2MSFTNGP04.phx.gbl...
The "socket.Receive" method doesn't include a time out parameter so are
there another ways to do it?

Thanks
Ole

"<ctacke/>" <ctacke_AT_OpenNETCF_com> wrote in message
news:O3**************@TK2MSFTNGP05.phx.gbl...
1. Make it a Background thread (set the IsBackground proeprty)
2. Use timeouts in your wait that periodically come back to see if it
should end
3. Wait on multiple items, like data receive and a quit event

-Chris

"Ole" <ol*@blabla.com> wrote in message
news:Oo**************@TK2MSFTNGP04.phx.gbl...
CF2.0
VS2005
C#

How to stop a worker thread that is e.g. listening for data on a port
when the application is closed?

Thanks,
Ole



May 29 '06 #6

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

Similar topics

5
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...
7
by: Jeff Stewart | last post by:
I need a thread to run a subroutine which updates my main form's progress bar. I've properly marshaled all UI updates to the main UI thread, and after the main thread starts the worker thread, it...
7
by: Charles Law | last post by:
My first thought was to call WorkerThread.Suspend but the help cautions against this (for good reason) because the caller has no control over where the thread actually stops, and it might have...
6
by: Joe Jax | last post by:
I have an object that spawns a worker thread to process one of its methods. That method processes methods on a collection of other objects. During this processing, a user may request to cancel the...
5
by: Soren S. Jorgensen | last post by:
Hi, In my app I've got a worker thread (background) doing some calculations based upon user input. A new worker thread might be invoked before the previous worker thread has ended, and I wan't...
14
by: joey.powell | last post by:
I am using VS2005 for a windows forms application. I need to be able to use a worker thread function to offload some processing from the UI thread. The worker thread will need access to a...
0
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...
6
by: Zytan | last post by:
I have code running in the debugger as I type. I press pause, and it pauses on: Application.Run(new myForm()); *I believe* a worker thread is in deadlock (it's in a lock, but calls another...
12
by: Zytan | last post by:
Can I break the debugger into a worker thread? Right now, my app is freezing, and when I press pause, it stops on: Application.Run(new MyForm()); I don't know what that means. I know the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.