Hello Tec.
 

匿名委托(方法) 以 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();
}
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();
}

相关文章:

  • 2021-08-09
  • 2022-03-01
  • 2022-02-03
  • 2022-02-10
  • 2022-12-23
  • 2022-12-23
  • 2021-10-20
  • 2021-09-01
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-17
  • 2021-10-19
  • 2022-12-23
相关资源
相似解决方案