Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 30th, 2012  |  syntax: C#  |  size: 1.04 KB  |  hits: 27  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. // הכללה של מרחב השמות העוסק בריבוי משימות
  7. using System.Threading;
  8.  
  9. namespace ThreadsExample
  10. {
  11.     class Program
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.             // יצירת משימה שאחראית על הפעלת הפונקציה
  16.             // WriteY
  17.             Thread t = new Thread(WriteY);
  18.             // הפעלת המשימה. מכאן המשימה מתחילה לרוץ ברקע
  19.             t.Start();
  20.  
  21.             // לולאה שמתבצעת לתמיד
  22.             while (true)
  23.             {
  24.                 // הדפסת התו
  25.                 // X
  26.                 Console.Write("X");
  27.             }
  28.         }
  29.  
  30.         private static void WriteY()
  31.         {
  32.             // לולאה שמתבצעת לתמיד
  33.             while (true)
  34.             {
  35.                 // הדפסת התו
  36.                 // Y
  37.                 Console.Write("Y");
  38.             }
  39.         }
  40.     }
  41. }