clear a WaitHandle?

Posted on 2011-10-04
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 85

    Accepted Solution

    "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!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box? As …
    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now