美文网首页
C# 线程传参数 利用lambda表达式

C# 线程传参数 利用lambda表达式

作者: 我是Mr小赵先生 | 来源:发表于2018-01-05 17:28 被阅读584次

using System;
using System.Threading;

namespace ThreadWithParameters
{
class Program
{
static void Main(string[] args)
{
string hello = "hello world";

        //如果写成Thread thread = new Thread(ThreadMainWithParameters(hello));这种形式,编译时就会报错
        Thread thread = new Thread(() => ThreadMainWithParameters(hello));
        thread.Start();

        Console.Read();
    }

    static void ThreadMainWithParameters(string str)
    {
         Console.WriteLine("Running in a thread,received: {0}", str);
    }
}

}

相关文章

网友评论

      本文标题:C# 线程传参数 利用lambda表达式

      本文链接:https://www.haomeiwen.com/subject/udpsnxtx.html