hi guys..
anyone encounter this problem ?,... here it's goes.
look at the Start and Stop Method. I have set the variable str_Value="Stop
Command Triggerred"
on the Stop Function. then Start the Service again.. by right the
EventLog.WriteEntry(str_Value) should be
writing "Stop Command Triggerred" in the Event Viewer Console cos my string
variables is declared
within the constructer and not inside the method. but apparently it turns
out differently.
I have got "Default Command Triggerred" from the Event Viewer Console.
protected override void OnStart(string[] args)
{
EventLog.WriteEntry(str_Value);
}
protected override void OnStop()
{
str_Value="Stop Command Triggerred";
}
Full Source Code here -
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
namespace WindowsService
{
public class Service1 : System.ServiceProcess.ServiceBase
{
private System.ComponentModel.IContainer components;
private string str_Value="Default Command Triggerred";
public Service1()
{
InitializeComponent();
}
static void Main()
{
System.ServiceProcess.ServiceBase[] ServicesToRun;
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new
Service1() };
System.ServiceProcess.ServiceBase.Run(ServicesToRun);
}
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
this.ServiceName = "Service1";
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
protected override void OnStart(string[] args)
{
EventLog.WriteEntry(str_Value);
}
protected override void OnStop()
{
str_Value="Stop Command Triggerred";
}
}
|