TSR Windows c# Service

  • Thread starter Thread starter Warning: Incoming Airstrike!
  • Start date Start date
Warning: Incoming Airstrike! said:
How do I set up a program inside of a windows service to run to a point
and stop, to allow it to respond to events?

Windows Services generally just start a new thread when they're asked
to start, and stop it in a timely manner when they're asked to stop.
You do that in the same way you would for any other multi-threaded
application.
 
Jon said:
Windows Services generally just start a new thread when they're asked
to start, and stop it in a timely manner when they're asked to stop.
You do that in the same way you would for any other multi-threaded
application.

good answer...i think this is more what I was after:

http://www.fawcette.com/archives/premier/mgznarch/vbpj/2001/08aug01/ce0108/ce0108-2.asp


Create and Control Windows Services

Harness the power of the .NET Framework and VC#.NET to create and
control Microsoft Windows Services easily.

--
Texeme Textcasting Technology
http://texeme.com

Indie Pop Rocks @ SomaFM
http://somafm.com/
 
Jon said:
Sorry, I assumed you'd already got the service bit up and running and
just wanted to know about the threading part.

No, it was just my logical understanding of how a service operates.

I got the app running, but it relies on a Console.Readline to "hang"
there and wait for events in a Main method.

So, I broke up everything before the .Readline and put that in the
service Start() and everything after in the Stop().

I started to think about the service more like a windows form, that just
starts and loads "stuff" ( like a form ) and waits there, until you
"exit" it ( service.Stop() ).

It seems to work -- but honestly, I still don't exactly understand.


--
Texeme Textcasting Technology
http://texeme.com

Indie Pop Rocks @ SomaFM
http://somafm.com/
 
!!! Klutzo !!! said:
No, it was just my logical understanding of how a service operates.

Ah, right.
I got the app running, but it relies on a Console.Readline to "hang"
there and wait for events in a Main method.

The Main method should create an array of services it is capable of
running, and call System.ServiceProcess.ServiceBase.Run, I believe. The
service controller will then start the service. This is the confusing
part, IMO.
So, I broke up everything before the .Readline and put that in the
service Start() and everything after in the Stop().

I started to think about the service more like a windows form, that just
starts and loads "stuff" ( like a form ) and waits there, until you
"exit" it ( service.Stop() ).

It seems to work -- but honestly, I still don't exactly understand.

Well, once it's installed, the service controller loads and starts it
when you ask it to, and the OnStart method is called. You should
process this method quickly, starting other threads to do your normal
work, so that the service control manager isn't hanging around for ages
waiting to know whether or not the service has started.

When the service controller wants it to stop (either through user
action or programmatically) the OnStop method is called, and you should
at that point stop all the threads you've started, and return.
 
Back
Top