Link to home
Start Free TrialLog in
Avatar of deleyd
deleydFlag for United States of America

asked on

clear a WaitHandle?

I have a file watcher notifying me when a file changes:
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);
  .
  .
}

Open in new window

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
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial