Where can I find sample C# code for simple threading?

Where can I find sample C# code for simple threading?

  • Comments 11

Refer to the System.Threading namespace on MSDN for full details. Meanwhile here is a quick taste.

using System; 
using System.Threading; 

class ThreadTest 
{ 
    public void Runme() 
    { 
        Console.WriteLine("Runme Called"); 
        Thread.Sleep(10000); 
    }

    public static void Main(String[] args)
    { 
        ThreadTest b = new ThreadTest(); 
        Thread t = new Thread(new ThreadStart(b.Runme)); 
        t.Start(); 

        Console.WriteLine("Thread 't' started.");
Console.WriteLine("
There is no telling when " +
"'Runme' will be invoked. "); t.Join(); Console.WriteLine("Thread 't' has ended."); } }
[Author: Santosh Zachariah]
Leave a Comment
  • Please add 5 and 8 and type the answer here:
  • Post
Page 1 of 1 (11 items)