Click here to Skip to main content
15,918,303 members
Home / Discussions / C#
   

C#

 
QuestionWindows Service, FileSystemWatcher + Polling [modified] Pin
krazykoder2-Mar-10 6:23
krazykoder2-Mar-10 6:23 
AnswerRe: Windows Service, FileSystemWatcher + Polling Pin
Paulo Zemek2-Mar-10 6:36
Paulo Zemek2-Mar-10 6:36 
GeneralRe: Windows Service, FileSystemWatcher + Polling Pin
PIEBALDconsult2-Mar-10 8:50
mvePIEBALDconsult2-Mar-10 8:50 
GeneralRe: Windows Service, FileSystemWatcher + Polling Pin
Paulo Zemek2-Mar-10 9:48
Paulo Zemek2-Mar-10 9:48 
GeneralRe: Windows Service, FileSystemWatcher + Polling Pin
krazykoder2-Mar-10 10:55
krazykoder2-Mar-10 10:55 
GeneralRe: Windows Service, FileSystemWatcher + Polling Pin
PIEBALDconsult2-Mar-10 12:38
mvePIEBALDconsult2-Mar-10 12:38 
GeneralRe: Windows Service, FileSystemWatcher + Polling Pin
krazykoder2-Mar-10 9:23
krazykoder2-Mar-10 9:23 
GeneralRe: Windows Service, FileSystemWatcher + Polling [modified] Pin
Paulo Zemek2-Mar-10 9:39
Paulo Zemek2-Mar-10 9:39 
You will need two more threads.

The original thread deals with the OnStart, OnStop and the FileSystemWatcher event.
One thread deals with the "time by time lookup in the directory"
And one thread deals with the real processing.

The stopRequested is a volatile bool. In OnStop you must set it to true and also call manualResetEvent.Set(), so it can check that stop was requested (instead of being kept in wait mode) and return.

It will be good to have another manualResetEvent. So, in the thread that runs from time to time, instead of calling Thread.Sleep(60000) you will call
otherManualResetEvent.WaitOne(60000);

So, in OnStop you set it and it returns immediatelly and, when it is running, it will have the time-out after 60 seconds and will execute again.

The stopRequested must be set to true before setting the events, or else you can end-up in a situation where you set the event, it tries to run, does nothing, resets the event and then you set the variable... so your thread will not exit.
modified on Tuesday, March 2, 2010 3:49 PM

GeneralRe: Windows Service, FileSystemWatcher + Polling Pin
krazykoder3-Mar-10 9:32
krazykoder3-Mar-10 9:32 
GeneralRe: Windows Service, FileSystemWatcher + Polling Pin
Paulo Zemek3-Mar-10 13:33
Paulo Zemek3-Mar-10 13:33 
GeneralRe: Windows Service, FileSystemWatcher + Polling [modified] Pin
krazykoder4-Mar-10 6:26
krazykoder4-Mar-10 6:26 
GeneralRe: Windows Service, FileSystemWatcher + Polling Pin
krazykoder4-Mar-10 8:41
krazykoder4-Mar-10 8:41 
GeneralRe: Windows Service, FileSystemWatcher + Polling Pin
Paulo Zemek4-Mar-10 16:05
Paulo Zemek4-Mar-10 16:05 
GeneralRe: Windows Service, FileSystemWatcher + Polling Pin
krazykoder5-Mar-10 4:36
krazykoder5-Mar-10 4:36 
AnswerRe: Windows Service, FileSystemWatcher + Polling Pin
PIEBALDconsult2-Mar-10 8:44
mvePIEBALDconsult2-Mar-10 8:44 
AnswerRe: Windows Service, FileSystemWatcher + Polling Pin
Pete O'Hanlon2-Mar-10 10:23
mvePete O'Hanlon2-Mar-10 10:23 
GeneralRe: Windows Service, FileSystemWatcher + Polling Pin
#realJSOP3-Mar-10 3:54
professional#realJSOP3-Mar-10 3:54 
QuestionOUTLFLTR.DLL library - need an answer Pin
chiky_ancutza2-Mar-10 5:20
chiky_ancutza2-Mar-10 5:20 
AnswerRe: OUTLFLTR.DLL library - need an answer Pin
Dan Mos2-Mar-10 5:24
Dan Mos2-Mar-10 5:24 
GeneralRe: OUTLFLTR.DLL library - need an answer Pin
chiky_ancutza2-Mar-10 5:28
chiky_ancutza2-Mar-10 5:28 
GeneralRe: OUTLFLTR.DLL library - need an answer Pin
Dan Mos2-Mar-10 5:38
Dan Mos2-Mar-10 5:38 
AnswerRe: OUTLFLTR.DLL library - need an answer Pin
Luc Pattyn2-Mar-10 5:29
sitebuilderLuc Pattyn2-Mar-10 5:29 
AnswerRe: OUTLFLTR.DLL library - need an answer Pin
Covean2-Mar-10 5:33
Covean2-Mar-10 5:33 
GeneralRe: OUTLFLTR.DLL library - need an answer Pin
chiky_ancutza2-Mar-10 5:45
chiky_ancutza2-Mar-10 5:45 
GeneralRe: OUTLFLTR.DLL library - need an answer Pin
Covean2-Mar-10 5:58
Covean2-Mar-10 5:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.