Exemple d’utilisation de la classe ‘Mutex’

Author:


{filelink=17376}

using System;
using System.Threading;
<a href="sakoba.byethost13.com">voir ici
class ExempleMutex
{
    static Mutex objetMutex;

    public static void Main()
    {
        objetMutex = new Mutex(true, "AAA");
        ExempleMutex nm = new ExempleMutex();
        Thread t = new Thread(new ThreadStart(nm.Run));
        t.Start();
        Thread.Sleep(5000);
        objetMutex.ReleaseMutex();
        objetMutex.WaitOne();
    }

    public void Run()
    {
        Console.WriteLine("Thread Lancé");
        objetMutex.WaitOne();
        Console.WriteLine("Pause de 5 secondes");
        Thread.Sleep(5000);
        Console.WriteLine("Fin d'exécution de Thread");
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *