clear a WaitHandle?

Posted on 2011-10-04
Medium Priority
Last Modified: 2012-05-12
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)

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?
Question by:deleyd
1 Comment
LVL 86

Accepted Solution

Mike Tomlinson earned 2000 total points
ID: 36913612
"Is there a way I can reset InputEvt before waiting on it?"

Use the method of the same name, Reset():

    "Sets the state of the event to nonsignaled, causing threads to block."



*Note that your description is using InputEvt while your code is using abcInputEvt!

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month15 days, 1 hour left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question