Threading
-
I am using file watcher and a timer in a windows service and i want that timer_elapsed function should be called only when any file sytem watcher event is not working.i think it can be done using threading if i will assign lowest priority to the timer_elapsed thread.but i am not able to do it. can anybody can tell me how to do it in C#.
-
I am using file watcher and a timer in a windows service and i want that timer_elapsed function should be called only when any file sytem watcher event is not working.i think it can be done using threading if i will assign lowest priority to the timer_elapsed thread.but i am not able to do it. can anybody can tell me how to do it in C#.
-
I am using file watcher and a timer in a windows service and i want that timer_elapsed function should be called only when any file sytem watcher event is not working.i think it can be done using threading if i will assign lowest priority to the timer_elapsed thread.but i am not able to do it. can anybody can tell me how to do it in C#.
In C# the easiest way to accomplish this is to use a lock on an object.
private static object sLock = new object(); private void Timer\_elapsed(object source, EventArgs e) { lock (sLock) { //Timer code here. } } private void FileWatcher\_event(object source, EventArgs e) { lock (sLock) { //File code here. } }
any code in the lock blocks is protected from multiple threads accessing it at the same time. I do something similar with the timer that I wrote: http://www.codeproject.com/dotnet/ABTransClockArticle.asp[^]
I can imagine the sinking feeling one would have after ordering my book, only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon