线程的几种写法

1、第一种写法

Thread thread = new Thread(MyMethod);

static void MyMethod()

{

  console.write("我是不带参数的委托方法");

}

thread.start();

2、第二种写法,匿名委托:

Thread thread2= new Thread(delegate(){

  console.write("我是匿名的委托方法");

});

thread2.start();

3、第三种写法 lamda表达式

Thread thread3 = new Thread(()=>{

  console.write("传入空参,返回为空");

});

 注:多线程一般放在后台运行,这样在主程序退出时,线程就结束了。

thread.IsBackground=true;

posted @ 2020-04-30 23:20  boenotuch  阅读(854)  评论(0)    收藏  举报