C# Thread实例
来源:互联网 发布:unity3d发布webplayer 编辑:程序博客网 时间:2024/05/17 05:05
From URI: http://msdn.microsoft.com/zh-cn/library/system.threading.thread.aspx
using System.Threading;
// Simple threading scenario: Start a static method running
// on a second thread.
public class ThreadExample {
// The ThreadProc method is called when the thread starts.
// It loops ten times, writing to the console and yielding
// the rest of its time slice each time, and then ends.
public static void ThreadProc() {
for (int i = 0; i < 10; i++) {
Console.WriteLine("ThreadProc: {0}", i);
// Yield the rest of the time slice.
Thread.Sleep(0);
}
}
public static void Main() {
Console.WriteLine("Main thread: Start a second thread.");
// The constructor for the Thread class requires a ThreadStart
// delegate that represents the method to be executed on the
// thread. C# simplifies the creation of this delegate.
Thread t = new Thread(new ThreadStart(ThreadProc));
// Start ThreadProc. Note that on a uniprocessor, the new
// thread does not get any processor time until the main thread
// is preempted or yields. Uncomment the Thread.Sleep that
// follows t.Start() to see the difference.
t.Start();
//Thread.Sleep(0);
for (int i = 0; i < 4; i++) {
Console.WriteLine("Main thread: Do some work.");
Thread.Sleep(0);
}
Console.WriteLine("Main thread: Call Join(), to wait until ThreadProc ends.");
t.Join();
Console.WriteLine("Main thread: ThreadProc.Join has returned. Press Enter to end program.");
Console.ReadLine();
}
}
- C# Thread实例
- C# Thread
- C# Thread
- C# Thread
- C# Thread
- C# Thread
- C# Thread
- c# Thread
- c# thread
- Java Thread 用法实例
- android thread实例
- Thread原理+实例说明
- android thread实例
- android thread实例
- android thread实例
- Thread 控制资源实例
- Thread实例讲解
- Thread中的实例方法
- VS2010 几个不常用,却很有用的快捷键
- Django笔记-generic views
- iOS常用的几个基础类 一个不用xib文件的例子
- 揭秘微软将进行开源的10大证据
- ubuntu下利用SSH登录git(转载)
- C# Thread实例
- 通过httpurlconnection发带图片的文件
- Django笔记-Forms
- 转: Precompilation Run Script in Xcode 4
- typeid详解
- 代码风格的问题
- Django笔记-Admin
- 一些VC的快捷键以及调试方法技巧
- 一个不起眼的手误,让我调了半小时