线程操作之创建线程

C#中创建线程的路程

1.先创建一个ThreadStart委托实例

2.在以这个ThreadStart委托作为参数,来构造Thread实例。

class Program
    {
        public static void meth()
        {
            //创建委托方法
            for (int i = 1; i < 100; i++)
            {
                Console.WriteLine(i);
            }

        }
        static void Main(string[] args)
        {
            //利用委托来传递值
            ThreadStart ht = new ThreadStart(meth);

            //通过构造函数来创建线程实例

            Thread th = new Thread(ht);
            th.Start();
            Console.Read();
        }
    }

猜你喜欢

转载自www.cnblogs.com/xiaowie/p/9132813.html