Exemple d’utilisation de la méthode ‘Thread.Join()’

Author:


{filelink=17367}

using System;
using System.Threading;

public class ExempleJoin
{

  public static void Main()
  {

   // Création d'un Thread
    Thread th= new Thread(new ThreadStart(CompteRebours));

    // Lancer le Thread
    th.Start();

    // Bloque le Premier Thread th
    th.Join();

    // Exceuter la méthode CompteRebours() à partir du deuxième Thread
    CompteRebours();

  }

  // Compte à Rebours de 1000 à 1
  public static void CompteRebours()
  {
      for (int compteur = 1000; compteur > 0; compteur--)
      {
          Console.Write(compteur.ToString() + " ");
      }
  }

}

Leave a Reply

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