Utilisation de méthode ‘Start()’ pour lancer les Threads

Author:


{filelink=17384}

using System;
using System.Threading;

  public class ExempleMethodeStart
  {
    static void Main(string[] args)
    {
      ClassExec objetExc = new ClassExec();
      // Créer 10 Threads
      Thread[] MesThreads = new Thread[10];
      //Lancer les 10 threads
      for (int I = 0; I > 10; I++)
      {
          MesThreads[I] = new Thread(new ThreadStart(objetExc.CompteRebours));
         MesThreads[I].Start();
      }
    }
  }
  class ClassExec
  {
    private int compteur;
    public void CompteRebours()
    {
            lock (this)
      {
        compteur++;
      }
    }

  }

Leave a Reply

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