Hi
I've written a Windows Service which has
- several (0-100) listeners threads which spawn worker threads based on
events, timers etc
- several (0-300) worker threads which handle data (message based) and
terminate after processing
I'm wondering what exactly happens when I stop the service. I don't see an
ThreadAbortedException, but I'm worried my worker threads might be
terminated in the middle of processing. My Server.OnStop is empty.
Does Windows wait for all threads to terminate in a given timespan, then
send an Abort to all running threads? Or does it send Abort directly?
Any help, including pointing to good URL (haven't found any so far) or
better newsgroup is very much appreciated.
Simon 2 7188
Inline
Willy.
"Simon Niederberger" <si***@sincore.ch> wrote in message
news:Om*************@TK2MSFTNGP14.phx.gbl... Hi
I've written a Windows Service which has - several (0-100) listeners threads which spawn worker threads based on events, timers etc - several (0-300) worker threads which handle data (message based) and terminate after processing
Such high number of threads is just a waste of CPU and memory resources, you
can do with far less than that.
I'm wondering what exactly happens when I stop the service. I don't see an ThreadAbortedException, but I'm worried my worker threads might be terminated in the middle of processing. My Server.OnStop is empty.
Does Windows wait for all threads to terminate in a given timespan, then send an Abort to all running threads? Or does it send Abort directly?
The OS doesn't send anything at all, the CLR stops the threads cold by
issuing a Thread.Abort as part of the CLR's orderly shutdown procedure. If
this is not what you want, you should handle your thread shutdown yourself
in OnStop. One way of doing this is to have your threads inspect a shared
flag that you could set in OnClose, once the flag set, the active thread
should stop it's activity and return, the OnStop procedure can use
Thread.Join(timeout) on each thread you have started.
Note that all this should be done within 30 seconds, as otherwise the SCM
will consider that the service failed to shutdown.
Any help, including pointing to good URL (haven't found any so far) or better newsgroup is very much appreciated.
Simon
Thanks a lot, perfect answer (within hours!) I'll look into reducing the
number of threads, but I feel that won't be to easy.
Cheers
Simon
"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:ui**************@TK2MSFTNGP09.phx.gbl... Inline
Willy.
"Simon Niederberger" <si***@sincore.ch> wrote in message news:Om*************@TK2MSFTNGP14.phx.gbl... Hi
I've written a Windows Service which has - several (0-100) listeners threads which spawn worker threads based on events, timers etc - several (0-300) worker threads which handle data (message based) and terminate after processing
Such high number of threads is just a waste of CPU and memory resources,
you can do with far less than that.
I'm wondering what exactly happens when I stop the service. I don't see
an ThreadAbortedException, but I'm worried my worker threads might be terminated in the middle of processing. My Server.OnStop is empty.
Does Windows wait for all threads to terminate in a given timespan, then send an Abort to all running threads? Or does it send Abort directly? The OS doesn't send anything at all, the CLR stops the threads cold by issuing a Thread.Abort as part of the CLR's orderly shutdown procedure. If this is not what you want, you should handle your thread shutdown yourself in OnStop. One way of doing this is to have your threads inspect a shared flag that you could set in OnClose, once the flag set, the active thread should stop it's activity and return, the OnStop procedure can use Thread.Join(timeout) on each thread you have started. Note that all this should be done within 30 seconds, as otherwise the SCM will consider that the service failed to shutdown. Any help, including pointing to good URL (haven't found any so far) or better newsgroup is very much appreciated.
Simon
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: B Moor |
last post by:
SServer PC: Win SBS 2003 with 2.6 GHz processor and 1GB RAM
SQL Server 2000 v 2000.8.00.76 (sp3)
MS Office 2k3
MSJet ms04-014 (latest ost sp8)
MDAC v2.8 RTM
ADO 2.1
vb6.exe / ADO 2.0
I...
|
by: Leandro Berti via DotNetMonster.com |
last post by:
Hi All,
I wrote a code to do serial communication with an equipament.
When i use the code outside of threaded class it seens work properly,
but when i put inside a class and execute a thread in...
|
by: Aaron Smith |
last post by:
What is the best way to handle data in a multiple user environment? We
have forms that will allow users to add edit and delete data from a
table on SQL server. The data could be edited on multiple...
|
by: Niels Jensen |
last post by:
Hi,
I'm a bit of a newbie to VB.NET so please forgive me if I get the
terminology incorrect... I'm still learning :)
I have a form with five numUpDown controls representing different ratios...
|
by: Jackson Peebles |
last post by:
Hey everyone! I'm a complete newbie to PHP, and am trying to teach
myself how to make some scripts. So far I've done pretty good, but
even after searching through all my books, articles, manuals,...
|
by: rapin |
last post by:
How do you make javascript’s string functions (like toUpperCase() or substr()) run under SpiderMonkey to handle multi-byte characters.
For example:
var strTest = "ørnen på";
var ...
|
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...
|
by: Rui Maciel |
last post by:
I want to support Unicode on a pet project of mine (small markup language
parser). I've read a bit about Unicode (didn't delved beyond the basics)
and I searched for some info on how to support...
|
by: dmoore |
last post by:
Hi folks,
I've seen the following issue come up in multiple posts to this
mailing list:
I have a python program that spawns a child process with popen or
popen2 or popen3 or popen2.popen2...
|
by: MartinRinehart |
last post by:
Thinking about unclosed multi-line quotes.
When you open a multi-line quote (type '"""') what does your editor
do? Does it color the remainder of your text as a quote, or does it
color the line...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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...
|
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,...
|
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...
|
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...
| |