匿名委托(方法) 以 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 2014-08-09 14:30 Kevin Kim 阅读(7123) 评论(1) 编辑 收藏 举报
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步