Exemple d’utilisation des propriétés de ‘ThreadPriority’

Author:


{filelink=17369}

using System;
using System.Threading;

public class ExemplePriority
{

  public static void Main()
  {

    // Création de notre Thread
    Thread th = new Thread(new ThreadStart(CompteRebours));

    // Attribuer la plus grande priorité (highest) à notre Thread
    th.Priority=ThreadPriority.Highest;

    // Attribuer une priorité faible au thread en cours d'exécution
    // Ce la ne concerne pas notre Thread
    Thread.CurrentThread.Priority=ThreadPriority.Lowest;

    // Lancer le Thread crée
    th.Start();

    // Lancer la méthode Compte à rebours dans un autre 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 *