Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

WaitHandle.WaitTimeout Field

Indicates that a WaitAny operation timed out before any of the wait handles were signaled. This field is constant.

Namespace:  System.Threading
Assembly:  mscorlib (in mscorlib.dll)

public const int WaitTimeout

This field is one of the possible return values of WaitAny.

The following code example demonstrates how to use the thread pool to simultaneously search for a file on multiple disks. For space considerations, only the root directory of each disk is searched.

using System;
using System.IO;
using System.Threading;

class Test
    static void Main()
        Search search = new Search();

class Search
    // Maintain state information to pass to FindCallback. 
    class State
        public AutoResetEvent autoEvent;
        public string         fileName;

        public State(AutoResetEvent autoEvent, string fileName)
            this.autoEvent    = autoEvent;
            this.fileName     = fileName;

    AutoResetEvent[] autoEvents;
    String[] diskLetters;

    public Search()
        // Retrieve an array of disk letters.
        diskLetters = Environment.GetLogicalDrives();

        autoEvents = new AutoResetEvent[diskLetters.Length];
        for(int i = 0; i < diskLetters.Length; i++)
            autoEvents[i] = new AutoResetEvent(false);

    // Search for fileName in the root directory of all disks. 
    public void FindFile(string fileName)
        for(int i = 0; i < diskLetters.Length; i++)
            Console.WriteLine("Searching for {0} on {1}.",
                fileName, diskLetters[i]);
                new WaitCallback(FindCallback), 
                new State(autoEvents[i], diskLetters[i] + fileName));

        // Wait for the first instance of the file to be found. 
        int index = WaitHandle.WaitAny(autoEvents, 3000, false);
        if(index == WaitHandle.WaitTimeout)
            Console.WriteLine("\n{0} not found.", fileName);
            Console.WriteLine("\n{0} found on {1}.", fileName,

    // Search for stateInfo.fileName. 
    void FindCallback(object state)
        State stateInfo = (State)state;

        // Signal if the file is found. 

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8
© 2015 Microsoft