在C#中如何启动一个新线程

我们可以使用newthreadstart委托创建一个新线程。
此委托将参考新线程执行的方法。
最后,我们可以调用thread.start方法来运行该方法。

在C#中开启新线程示例

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading; 

namespace ThreadStart

{

    class Program

    {

        static void Main(string[] args)

        {

            Thread th = new Thread(new ThreadStart(WriteY));

            th.Start();

            for (int i = 0; i <= 10; i++)

            {

                Console.WriteLine("Hello");

            }

            Console.ReadLine();

        }

        static void WriteY()

        {

            for (int i = 0; i <= 9; i++)

            {

                Console.Write("HI");

            }

        } 

    }

}
日期:2020-04-11 23:03:52 来源:oir作者:oir