deleyd
asked on
clear a WaitHandle?
I have a file watcher notifying me when a file changes:
I can only guess that my file watcher fired once before, awhile ago, before I became interested in watching for a file change, and that previous change has already set InputEvt to true.
Is there a way I can reset InputEvt before waiting on it? Or is there a way I can test InputEvt to see if it is set or not, to see if that is indeed the problem?
static AutoResetEvent InputEvt = new AutoResetEvent(false);
private void fileSystemWatcher1_Changed(object sender, FileSystemEventArgs e)
{
.
.
InputEvt.Set();
}
private bool ReadReply(int timeoutSeconds)
{
int milliseconds = timeoutSeconds * 1000;
WaitHandle[] syncobjects = new WaitHandle[1] { abcInputEvt };
int index = WaitHandle.WaitAny(syncobjects, milliseconds);
.
.
}
Problem is my ReadReply returns immediately instead of waiting for the file to change or the timeout to expire.I can only guess that my file watcher fired once before, awhile ago, before I became interested in watching for a file change, and that previous change has already set InputEvt to true.
Is there a way I can reset InputEvt before waiting on it? Or is there a way I can test InputEvt to see if it is set or not, to see if that is indeed the problem?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.