473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

How is the start sequence for windows service

Hello!!
Below I have written the main method, the C-tor and the OnStart.
Who is calling OnStart? It must be the operating system that calls it after
the C-tor has finished

1. Main is always started first
2. The C-tor is then called
3. The operating system is then calling OnStart
Here is my main for the service project.
*****************************
static void Main()
{
System.ServiceProcess.ServiceBase[] ServicesToRun;
// More than one user Service may run within the same process. To add
// another service to this process, change the following line to
// create a second service object. For example,
//
// ServicesToRun = new System.ServiceProcess.ServiceBase[] {new
Service1(), new MySecondUserService()};
//
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new
MyNewService() };
System.ServiceProcess.ServiceBase.Run(ServicesToRu n);
}
Here is the C-tor
*************
public MyNewService()
{
InitializeComponent();
if(!System.Diagnostics.EventLog.SourceExists("DoDy LogSourse"))
System.Diagnostics.EventLog.CreateEventSource("DoD yLogSourse",
"DoDyLog");

eventLog1.Source = "DoDyLogSourse";
// the event log source by which
// the application is registered on the computer

eventLog1.Log = "DoDyLog";
}

Here I have the OnStart
******************
protected override void OnStart(string[] args)
{
eventLog1.WriteEntry("my service started");
}
Sep 19 '07 #1
2 4893
"TonyJ" <jo*****************@telia.comschrieb im Newsbeitrag
news:O4****************@TK2MSFTNGP04.phx.gbl...
Hello!!
Below I have written the main method, the C-tor and the OnStart.
Who is calling OnStart? It must be the operating system that calls it
after
the C-tor has finished

1. Main is always started first
2. The C-tor is then called
3. The operating system is then calling OnStart
1. When the process is started, the Main method is run (like with every
exe).
2. The creator of the service class is called by the Main method (as you can
see in the code).

3. When the service is started, the OnStart method is called. This will
occur after then Main method has run.

The first 2 calls are down immediatly before the second, if the process was
started on behalf of that service. But it will not be repeated if the
process is allready running with another process.

You can debug the last call, by putting another service in the same
executable:
- Start the other service.
- Hook the debugger to the process.
- Set a breakpoint in the OnStart method (can be done earlier)
- Start the service.
>
Here is my main for the service project.
*****************************
static void Main()
{
System.ServiceProcess.ServiceBase[] ServicesToRun;
// More than one user Service may run within the same process. To add
// another service to this process, change the following line to
// create a second service object. For example,
//
// ServicesToRun = new System.ServiceProcess.ServiceBase[] {new
Service1(), new MySecondUserService()};
//
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new
MyNewService() };
System.ServiceProcess.ServiceBase.Run(ServicesToRu n);
}
Here is the C-tor
*************
public MyNewService()
{
InitializeComponent();
if(!System.Diagnostics.EventLog.SourceExists("DoDy LogSourse"))
System.Diagnostics.EventLog.CreateEventSource("DoD yLogSourse",
"DoDyLog");

eventLog1.Source = "DoDyLogSourse";
// the event log source by which
// the application is registered on the computer

eventLog1.Log = "DoDyLog";
}

Here I have the OnStart
******************
protected override void OnStart(string[] args)
{
eventLog1.WriteEntry("my service started");
}

Sep 19 '07 #2
Hello!

What do you mean here. I understand some of it but not all.
You can debug the last call, by putting another service in the same
executable:
Start the other service.
Hook the debugger to the process.
Set a breakpoint in the OnStart method (can be done earlier)
Start the service.

I have done the following
I have added another service in the project by using add new item and then
choose window service
from the template.

What else do I need if I want to be able to debug the OnStart?

//Tony

"Christof Nordiek" <cn@nospam.deskrev i meddelandet
news:uY**************@TK2MSFTNGP06.phx.gbl...
"TonyJ" <jo*****************@telia.comschrieb im Newsbeitrag
news:O4****************@TK2MSFTNGP04.phx.gbl...
Hello!!
Below I have written the main method, the C-tor and the OnStart.
Who is calling OnStart? It must be the operating system that calls it
after
the C-tor has finished

1. Main is always started first
2. The C-tor is then called
3. The operating system is then calling OnStart

1. When the process is started, the Main method is run (like with every
exe).
2. The creator of the service class is called by the Main method (as you
can
see in the code).

3. When the service is started, the OnStart method is called. This will
occur after then Main method has run.

The first 2 calls are down immediatly before the second, if the process
was
started on behalf of that service. But it will not be repeated if the
process is allready running with another process.

You can debug the last call, by putting another service in the same
executable:
- Start the other service.
- Hook the debugger to the process.
- Set a breakpoint in the OnStart method (can be done earlier)
- Start the service.

Here is my main for the service project.
*****************************
static void Main()
{
System.ServiceProcess.ServiceBase[] ServicesToRun;
// More than one user Service may run within the same process. To add
// another service to this process, change the following line to
// create a second service object. For example,
//
// ServicesToRun = new System.ServiceProcess.ServiceBase[] {new
Service1(), new MySecondUserService()};
//
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new
MyNewService() };
System.ServiceProcess.ServiceBase.Run(ServicesToRu n);
}
Here is the C-tor
*************
public MyNewService()
{
InitializeComponent();
if(!System.Diagnostics.EventLog.SourceExists("DoDy LogSourse"))
System.Diagnostics.EventLog.CreateEventSource("DoD yLogSourse",
"DoDyLog");

eventLog1.Source = "DoDyLogSourse";
// the event log source by which
// the application is registered on the computer

eventLog1.Log = "DoDyLog";
}

Here I have the OnStart
******************
protected override void OnStart(string[] args)
{
eventLog1.WriteEntry("my service started");
}

Sep 19 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Bryan | last post by:
We created a Windows Service with C#. The service will start OK on computers that are a member of a domain, but when we try to start it on a server that is configured for a workgroup we get the...
2
by: Mark | last post by:
I created an extremely simple windows service that only writes to the EventLogs on Stop and Pause. I installed it using the InstallUtil.exe program, the output of which is below. It appears to be...
12
by: GTi | last post by:
I have small program that always must be running when a user is logged on. Since users can close this program I must create a program that always check if this program is running. So I created a...
5
by: SiD` | last post by:
when starting a windows service writte in vb.net, a messagebox appears: cannot start service from the command line or a debugger. A windows service must first be installed using installutil.exe ...
6
by: Arnie | last post by:
We're using the ServiceController class provided by the .NET Framework, programming in C#. We are using the Start() method to start a service from another service. This works fine most of the...
3
by: tshad | last post by:
I created a service in VS 2003 and the code works fine as an application, but not as a service. It installs fine, but when I try to start it, it tells me it was unable to start. Am I missing...
7
by: shai | last post by:
I am working at .net 1.1, writing in c#. I have windows service with a COM object. Every unexpected time The COM object throw an error that make my service get stuck (do not respond). I can catch...
3
by: forest demon | last post by:
for example, let's say I do something like, System.Diagnostics.Process.Start("notepad.exe","sample.txt"); if the user does a SaveAs (in notepad), how can i capture the path that the user...
4
by: carson | last post by:
I have written two windows services: - service A does some crunching of local data files and uploads them to a central processing computer via http. - service B monitors a manifest file on a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.