473,511 Members | 14,933 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1838
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
2235
by: Michael Riggio | last post by:
Is there a way to have a windows service instantiate a class that is a web service, which will then be accessible to clients via HTTP? Thanks, -Mike
1
5657
by: Artur Kowalski | last post by:
I have a NotifyIcon in my Windows Service project and I am trying to add a ContextMenu to this NotifyIcon or use some of the mouse events. Everything isn't working. I think so base class of the...
9
7232
by: SP | last post by:
Hi All, I wrote a windows service which is supposed to stop after specified amount of time. I am calling OnStop() after specified time. OnStop() methods executed but I dont see the service...
1
3435
by: Scott Davies | last post by:
Hi, I'm looking for some help on a small program that I'm trying to develop in VB.NET. I'm having trouble getting the code that I've written to work, can anyone shed some light as to where I'm...
0
3906
by: Scott Davies | last post by:
Hi, I'm looking for some help on a small program that I'm trying to develop in VB.NET. The program I'm trying to develop needs to be able to do the following: - Select remote server -...
3
3667
by: Doug Bailey | last post by:
I am trying to control a Windows Service via a Web Service interface. (I am developing in .NET2003) I am using the ServiceController object which allows me to read the state of the services with...
2
6878
by: deko | last post by:
When to use a privileged user thread rather than a windows service? That's the question raised in a previous post . It was suggested that if the service needs to interact with a WinForms app...
4
4158
by: tshad | last post by:
What would be a good way to check programmatically whether a service was running? We have a service that dies periodically and I need to check to see if this service is running. I know how to...
5
3270
by: dm3281 | last post by:
I'm really starting to hate writing services -- or trying to, anyway. Why do I need to rename my project to the service name? Why do I need to set the "ServiceName" property to my service name?...
1
2069
by: =?Utf-8?B?TWFuanJlZSBHYXJn?= | last post by:
Hi, I created a web service that I want to host in windows service. The problem is that if I host it as windows service it does not use the configuration file. I have to define the binding,...
1
7074
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...
0
7506
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5659
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4734
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3219
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3210
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1572
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
445
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.