Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Exemple d’utilisation de la classe ‘Mutex’


{filelink=17376}

using System;
using System.Threading;
&lt;a href="sakoba.byethost13.com"&gt;voir ici</a>
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");
    }
}

No comments yet.

Leave a Comment