hey guys, I've followed some tutorials online regarding creating and installing a windows service and seem to keep getting into a bind. I followed the tutorial here and it while it seems to be working, its not 100%. This is the code im using:
namespace SuperService
{
partial class Logger : ServiceBase
{
public Logger()
{
InitializeComponent();
}
void timer1_Tick( object sender, EventArgs e )
{
LogEvent( "This Timer has been ticked!", EventLogEntryType.Information );
}
protected override void OnStart( string[] args )
{
timer1.Tick += new EventHandler( timer1_Tick );
timer1.Start();
LogEvent( "This SuperService has started!", EventLogEntryType.Information );
}
protected override void OnStop()
{
LogEvent( "This SuperService has stopped.", EventLogEntryType.Information );
}
protected override void OnPause()
{
base.OnPause();
timer1.Stop();
}
protected override void OnContinue()
{
base.OnContinue();
timer1.Start();
}
static void LogEvent( String Message, EventLogEntryType type )
{
String source = "Logger";
String log = "Application";
if (!EventLog.SourceExists( source ))
{
EventLog.CreateEventSource( source, log );
}
EventLog eLog = new EventLog();
eLog.Source = source;
eLog.WriteEntry( Message, type );
}
}
}
Now when I check the Event Viewer after starting the service it shows the following two events:
This SuperService has started!
Service started successfully.
So it seems to be working somewhat, what I dont see is the event triggered by timer1_Tick. Does anyone know why or can point me in the right direction pls? Thanks in advance.