线程开启方式——异步委托

        static void Main(string[] args)
        {
            Func<string, int> th = MyThreadMethod;
            //BeginInvoke参数说明:1-n为线程输入参数;n+1为回调函数;n+2为回调函数输入参数
            //使用Lambda表达式作为回调函数,获得子线程方法返回值
            th.BeginInvoke("Baby", ar =>
            {
                int res = th.EndInvoke(ar);
                Console.WriteLine($"子线程方法返回值:{res}");
            }, null);
            Console.WriteLine("主线程。。。");
            Console.ReadKey();
        }

        static int MyThreadMethod(string s)
        {
            Console.WriteLine($"子线程。。。输入参数s={s}");
            return 100;
        }

运行结果:

  主线程。。。
  子线程。。。输入参数s=Baby
  子线程方法返回值:100

原文地址:https://www.cnblogs.com/zhaoshujie/p/9630477.html