C# 多线程示例

Posted bobo-bobo

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C# 多线程示例相关的知识,希望对你有一定的参考价值。

static void Main(string[] args)
        {
            Thread t1 = new Thread(new ThreadStart(TestMethod));
            Thread t2 = new Thread(new ParameterizedThreadStart(TestMethod));
            t1.IsBackground = true;
            t2.IsBackground = true;
            t1.Start();
            t2.Start("hello");
            Console.ReadKey();
        }

        public static void TestMethod()
        {
            Console.WriteLine("不带参数的线程函数");
        }

        public static void TestMethod(object data)
        {
            string datastr = data as string;
            Console.WriteLine("带参数的线程函数,参数为:{0}", datastr);
        }

以上是关于C# 多线程示例的主要内容,如果未能解决你的问题,请参考以下文章