PC Review


Reply
Thread Tools Rate Thread

Stopping a threaded .Net service

 
 
Jim Adams
Guest
Posts: n/a
 
      24th Nov 2004
When a VB.Net windows service receives a Stop request, when does it
actually end? For example, when a service app spawns worker threads
that run for a period ranging from a few seconds to a few minutes, how
will a Stop request be handled.

Thanks,

Jim
 
Reply With Quote
 
 
 
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      24th Nov 2004
Jim Adams <(E-Mail Removed)> wrote:
> When a VB.Net windows service receives a Stop request, when does it
> actually end? For example, when a service app spawns worker threads
> that run for a period ranging from a few seconds to a few minutes, how
> will a Stop request be handled.


I believe it's basically up to you to stop the other threads. See
http://www.pobox.com/~skeet/csharp/t...shutdown.shtml for my
suggestions on orderly thread shutdown.

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
David Browne
Guest
Posts: n/a
 
      24th Nov 2004

"Jim Adams" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> When a VB.Net windows service receives a Stop request, when does it
> actually end? For example, when a service app spawns worker threads
> that run for a period ranging from a few seconds to a few minutes, how
> will a Stop request be handled.
>


That's your responsibility.

In your OnStop method you need to tear down the service. This includes
closing files, shutting down threads, etc. Threads marked as background
threads can be automatically terminated when your application is shut down,
but you should do this yourself. In OnStop you should signal then join each
thread you've spawned. After waiting for the threads to stop, you can
Interrupt them if they haven't finished, or you can let them continue.

David


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Unhandled exception in threaded windows service Jason Microsoft Dot NET Framework 3 30th Nov 2004 09:39 AM
Stopping processes when stopping Windows service. Glen Wolinsky Microsoft VB .NET 0 9th Nov 2004 08:24 PM
Threaded windows Service Joăo Santa Bárbara Microsoft Dot NET 1 7th May 2004 07:31 AM
Multi-threaded NT/W2K Service Question Randy Geyer Microsoft Dot NET 1 12th Jul 2003 01:04 PM
Multi-threaded NT/Win2K Service Question Randy Geyer Microsoft Dot NET 1 11th Jul 2003 11:02 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:41 PM.