The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Mutex Constructor (Boolean)


Initializes a new instance of the Mutex class with a Boolean value that indicates whether the calling thread should have initial ownership of the mutex.

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

public Mutex(
	bool initiallyOwned


Type: System.Boolean

true to give the calling thread initial ownership of the mutex; otherwise, false.

The following code example shows how a local Mutex object is used to synchronize access to a protected resource. The thread that creates the Mutex owns it initially.

// This example shows how a Mutex is used to synchronize access
// to a protected resource. Unlike Monitor, Mutex can be used with
// WaitHandle.WaitAll and WaitAny, and can be passed across
// AppDomain boundaries.

using System;
using System.Threading;

class Test
    // Create a new Mutex. The creating thread owns the
    // Mutex.
    private static Mutex mut = new Mutex(true);
    private const int numIterations = 1;
    private const int numThreads = 3;

    static void Main()
        // Create the threads that will use the protected resource.
        for(int i = 0; i < numThreads; i++)
            Thread myThread = new Thread(new ThreadStart(MyThreadProc));
            myThread.Name = String.Format("Thread{0}", i + 1);

        // Wait one second before allowing other threads to
        // acquire the Mutex.
        Console.WriteLine("Creating thread owns the Mutex.");

        Console.WriteLine("Creating thread releases the Mutex.\r\n");

    private static void MyThreadProc()
        for(int i = 0; i < numIterations; i++)

    // This method represents a resource that must be synchronized
    // so that only one thread at a time can enter.
    private static void UseResource()
        // Wait until it is safe to enter.

        Console.WriteLine("{0} has entered the protected area", 

        // Place code to access non-reentrant resources here.

        // Simulate some work.

        Console.WriteLine("{0} is leaving the protected area\r\n", 

        // Release the Mutex.

Universal Windows Platform
Available since 4.5
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Windows Phone Silverlight
Available since 8.0
Windows Phone
Available since 8.1
Return to top
© 2015 Microsoft