19 August 2006

Threading in C#

Posted by Mikhail Esteves under: C#; Tips .

C# supports parallel execution of code through multithreading. A thread is an independent execution path, able to run simultaneously with other threads.

A C# program starts in a single thread created automatically by the CLR and operating system (the “main” thread), and is made multi-threaded by creating additional threads. Here’s a simple example and its output:

class ThreadTest {
  static void Main() {
    Thread t = new Thread (WriteY);
    t.Start();                          // Run WriteY on the new thread
    while (true) Console.Write ("x");   // Write 'x' forever
  }

  static void WriteY() {
    while (true) Console.Write ("y");   // Write 'y' forever
  }
}

Read more



Leave a Reply

Browse

Photography

Projects

Pages

Calendar

August 2006
M T W T F S S
« Jul   Sep »
 123456
78910111213
14151617181920
21222324252627
28293031  

Categories

www.flickr.com

Use OpenDNS