匿名委托(方法) 以 ThreadStart 为例

REF:http://baike.baidu.com/view/2761370.htm?fr=aladdin
 
不使用匿名方法:
static void Main(string[] args)
{
Thread thread = new Thread(new ThreadStart(Run));
// 或 Thread thread = new Thread(Run); // c# 2.0 或以后版本支持
thread.Start();
}
static void Run()
{
// 要运行的代码 ...
}
使用匿名方法
static void Main(string[] args)
{
Thread thread = new Thread(delegate()
{
// 要运行的代码
});
// 或 Thread thread = new Thread(new ThreadStart(delegate()
//{
// // 要运行的代码
//}));
thread.Start();
}
使用Lambda 表达式
static void Main(string[] args)
{
Thread thread = new Thread(() =>
{
// 要运行的代码
});
// 或 Thread thread = new Thread(new ThreadStart(() =>
//{
// // 要运行的代码
//}));
thread.Start();
}

posted on   Kevin Kim  阅读(7123)  评论(1编辑  收藏  举报

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示