Hi everyboby,
i wrote a c# service that every XXX minute launch a working thread on
timer events, something like this:
private void timer_Elapsed ( object status )
{
// Worker thread
System.Threading.ThreadPool.QueueUserWorkItem
( new
System.Threading.WaitCallback( _timer_Elapsed ) );
}
I have a problem when the service is stopping: if the thread is running
(work on SQL db) I MUST wait the end of the thread before stop the
service. Probably i'll have to work on OnStop event, but how? Now my
onStop method only log the service stop.
this is my onstop method:
/// <summary>
/// Stop this service.
/// </summary>
protected override void OnStop()
{
string msg;
string context = "OnStop";
try
{
DumpWorkingParameters( "Service stopped",
context,
IMCleanLogDBLibrary.LogVerbosity.InfoLow,
false );
}
catch ( System.Exception ex )
{
try
{
msg = String.Format( "Service stopping error\r\n{0}",
ex.ToString() );
eventLog.WriteEntry( msg,
System.Diagnostics.EventLogEntryType.Error );
m_TheCleanLogDBmanager.InsertLogRecord(
IMCleanLogDBLibrary.LogVerbosity.Error,
context,
msg );
}
catch {}
}
}
thanks.
Matteo