海鸥航迹

学习之笔记,好文之收集。

导航

[导入]Where can I find sample C# code for simple threading?

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]

文章来源:http://blogs.msdn.com/csharpfaq/archive/2004/03/15/90082.aspx

posted on 2004-09-22 09:33  海天一鸥  阅读(739)  评论(1编辑  收藏  举报