c#多线程

来源:互联网 发布:阿里云客服怎么计薪资? 编辑:程序博客网 时间:2024/04/30 20:58

c#多线程

using System.Threading;
public Thread tr1;
上面是定义
tr1=new Thread(new ThreadStart(函数));//函数不要括号
tr1.Start();
上面是启动

tr1.Abort();
  Thread.Sleep(200);
退出与延时

//-线程带参数----------------------------------------------

using System;
using System.Threading;
namespace ParameterizedThreadStartTest
{
    class Program
    {
        static void Main(string[] args)
        {

            ParameterizedThreadStart myParameterizedThreadDelegate = new ParameterizedThreadStart(ThreadMethod);
            Thread myThread = new Thread(myParameterizedThreadDelegate);
            object o = "hello";
            myThread.Start(o);

        }

        private static void ThreadMethod(object o)
        {
            string str = o as string;
            Console.WriteLine(str);
        }
    }
}