Thread Class
来源:互联网 发布:淘宝网页模板代码 编辑:程序博客网 时间:2024/04/29 01:06
Come form MSDN
A process can create one or more threads to execute a portion of the program code associated with the process. Use a ThreadStart delegate or the ParameterizedThreadStart delegate to specify the program code executed by a thread. The ParameterizedThreadStart delegate allows you to pass data to the thread procedure
Through the following example we should know how to use those methods of Thread class
using System;
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();
}
}
- Thread Class
- Thread class
- Thread Class
- Thread management class
- Thread-Safe Class Design
- Java Language Class Thread
- public class TableBcpProcessor extends Thread
- Java's Thread——Thread class and Runnables
- Class.forName() 初始化、Thread.currentThread().getContextClassLoader().getResourceAsStream
- 区别:Thread.currentThread().getContextClassLoader() and Class.getClassLoader()
- Java Style Thread Class in C++
- Thread.currentThread().getContextClassLoader() and Class.getClassLoader()
- #2 Concurrent Programming - Thread-Safe Class Design
- 线程-Runnable interface and thread class
- Thread.currentThread().getContextClassLoader() and Class.getClassLoader()
- Thread.currentThread().getContextClassLoader() 和 Class.getClassLoader()区别
- 区别:Thread.currentThread().getContextClassLoader() and Class.getClassLoader()
- Thread.currentThread().getContextClassLoader() 和 Class.getClassLoader()区别
- sql server 2005 导出用户表数据字典(转载)
- 嵌入式Linux的LCD驱动(FB @ s3c2410)
- 空
- firefox中垂直居中的问题
- win32汇编:原来点击顶层菜单属于发送SYSCOMMAND消息啊!!!终于解决了!!!
- Thread Class
- Java之父黯然离职 开源将何去何从
- java常见面试题
- Lotus Notes程序设计随笔
- java 下载文件的方法(2)
- ECSHOP安装出错解决 (一)
- servlet方面知识
- 未来
- 三章 汇编语言程序设计