Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

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


{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++;
      }
    }
 
  }

No comments yet.

Leave a Comment