Stopping a threaded .Net service

  • Thread starter Thread starter Jim Adams
  • Start date Start date
J

Jim Adams

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
 
Jim Adams said:
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
 
Back
Top