472,111 Members | 2,006 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,111 software developers and data experts.

TSR Windows c# Service


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?

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

Indie Pop Rocks @ SomaFM
http://somafm.com/

Jul 21 '05 #1
5 1766
Warning: Incoming Airstrike! <se****************@tower.effeil> wrote:
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 Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2
Jon Skeet [C# MVP] wrote:
Warning: Incoming Airstrike! <se****************@tower.effeil> wrote:
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.


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

http://www.fawcette.com/archives/pre...8/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/

Jul 21 '05 #3
Warning: Incoming Airstrike! <se****************@tower.effeil> wrote:
Jon Skeet [C# MVP] wrote:
Warning: Incoming Airstrike! <se****************@tower.effeil> wrote:
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.


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

http://www.fawcette.com/archives/pre...2001/08aug01/c
e0108/ce0108-2.asp


Sorry, I assumed you'd already got the service bit up and running and
just wanted to know about the threading part.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #4
Jon Skeet [C# MVP] wrote:

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/

Jul 21 '05 #5
!!! Klutzo !!! <re**@klutzo.theclown.huh.huh.huh> wrote:
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.


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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Michael Riggio | last post: by
1 post views Thread by Artur Kowalski | last post: by
9 posts views Thread by SP | last post: by
1 post views Thread by Scott Davies | last post: by
reply views Thread by Scott Davies | last post: by
3 posts views Thread by Doug Bailey | last post: by
4 posts views Thread by tshad | last post: by
5 posts views Thread by dm3281 | last post: by
1 post views Thread by =?Utf-8?B?TWFuanJlZSBHYXJn?= | last post: by
reply views Thread by leo001 | last post: by

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.