T
tshad
If I start FileWatcher on a thread, do I need to kill it in the OnStop
method when someone presses stop?
I have the code:
ThreadStart st = new ThreadStart(InitializeFileWatcher);
workerThread = new Thread(st);
workerThread.Name = "Startup Thread for Label Print
Service";
//start the thread
workerThread.Start();
And the InitializFileWatcher:
private void InitializeFileWatcher()
{
fileWatcher = new FileSystemWatcher();
fileWatcher.Path =
ConfigurationManager.AppSettings["FolderToWatch"];
fileWatcher.NotifyFilter = NotifyFilters.FileName;
fileWatcher.Filter = "*.*";
fileWatcher.Created += HandleLabelsFromFileWatcher;
fileWatcher.EnableRaisingEvents = true;
}
I then have:
protected override void OnStop()
{
System.Diagnostics.EventLog.WriteEntry(this.ServiceName,
this.ServiceName + " stopped.",
System.Diagnostics.EventLogEntryType.Information);
}
Do I need to have something in my OnStop to either kill the thread and/or
stop the FileWatcher?
I find that when I do it this way, sometimes the Service will stop right
away or will never stop and I get an error - but the service is still in the
task managers window.
Thanks,
Tom
method when someone presses stop?
I have the code:
ThreadStart st = new ThreadStart(InitializeFileWatcher);
workerThread = new Thread(st);
workerThread.Name = "Startup Thread for Label Print
Service";
//start the thread
workerThread.Start();
And the InitializFileWatcher:
private void InitializeFileWatcher()
{
fileWatcher = new FileSystemWatcher();
fileWatcher.Path =
ConfigurationManager.AppSettings["FolderToWatch"];
fileWatcher.NotifyFilter = NotifyFilters.FileName;
fileWatcher.Filter = "*.*";
fileWatcher.Created += HandleLabelsFromFileWatcher;
fileWatcher.EnableRaisingEvents = true;
}
I then have:
protected override void OnStop()
{
System.Diagnostics.EventLog.WriteEntry(this.ServiceName,
this.ServiceName + " stopped.",
System.Diagnostics.EventLogEntryType.Information);
}
Do I need to have something in my OnStop to either kill the thread and/or
stop the FileWatcher?
I find that when I do it this way, sometimes the Service will stop right
away or will never stop and I get an error - but the service is still in the
task managers window.
Thanks,
Tom