R
Ryan Breakspear
Hi All,
I have a problem with a windows service. It seems to run happily for
sometimes hours, checking a database every second. It uses a timer and in
the _elapsed event, the timer is stopped, the processing is done, and the
timer is restarted. Errors are logged to the Event Log.
I don't know how or why the service stops working, but it still appears in
the processes list, but uses about half the amount of memory it was using
when it was working.
I have seen similar messages posted by people about C# services which stop
working but there doesn't seem to be an explanation. If you have any ideas
please let me know.
Below is the code from the _elapsed event of the timer (sorry about the bad
formatting)
Thanks in advance
Ryan
private void tmrService_Elapsed(object sender,
System.Timers.ElapsedEventArgs e)
{
// Stop the timer so this routine can't be called twice at the same time
tmrService.Stop();
CfdsServiceConnection ServiceConnection = null;
CfdsOptiTimeCOMManager OptiTime = null;
try
{
// Create database connection
ServiceConnection = new CfdsServiceConnection(FConnectionString);
// Do all processing here!!!!
OptiTime = new CfdsOptiTimeCOMManager(ServiceConnection.MainConnection,
elService);
OptiTime.ProcessNewReceived();
}
catch(Exception E)
{
// Add entry to Event log with error message
elService.WriteEntry(E.Message, EventLogEntryType.Error);
}
finally
{
// Make sure timer is started again or it'll never run!
tmrService.Start();
//Close connection if not null
if (ServiceConnection != null)
{
ServiceConnection.CloseConnection();
}
}
}
I have a problem with a windows service. It seems to run happily for
sometimes hours, checking a database every second. It uses a timer and in
the _elapsed event, the timer is stopped, the processing is done, and the
timer is restarted. Errors are logged to the Event Log.
I don't know how or why the service stops working, but it still appears in
the processes list, but uses about half the amount of memory it was using
when it was working.
I have seen similar messages posted by people about C# services which stop
working but there doesn't seem to be an explanation. If you have any ideas
please let me know.
Below is the code from the _elapsed event of the timer (sorry about the bad
formatting)
Thanks in advance
Ryan
private void tmrService_Elapsed(object sender,
System.Timers.ElapsedEventArgs e)
{
// Stop the timer so this routine can't be called twice at the same time
tmrService.Stop();
CfdsServiceConnection ServiceConnection = null;
CfdsOptiTimeCOMManager OptiTime = null;
try
{
// Create database connection
ServiceConnection = new CfdsServiceConnection(FConnectionString);
// Do all processing here!!!!
OptiTime = new CfdsOptiTimeCOMManager(ServiceConnection.MainConnection,
elService);
OptiTime.ProcessNewReceived();
}
catch(Exception E)
{
// Add entry to Event log with error message
elService.WriteEntry(E.Message, EventLogEntryType.Error);
}
finally
{
// Make sure timer is started again or it'll never run!
tmrService.Start();
//Close connection if not null
if (ServiceConnection != null)
{
ServiceConnection.CloseConnection();
}
}
}