T
TonyJ
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(ServicesToRun);
}
Here is the C-tor
*************
public MyNewService()
{
InitializeComponent();
if(!System.Diagnostics.EventLog.SourceExists("DoDyLogSourse"))
System.Diagnostics.EventLog.CreateEventSource("DoDyLogSourse",
"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");
}
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(ServicesToRun);
}
Here is the C-tor
*************
public MyNewService()
{
InitializeComponent();
if(!System.Diagnostics.EventLog.SourceExists("DoDyLogSourse"))
System.Diagnostics.EventLog.CreateEventSource("DoDyLogSourse",
"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");
}