线程实现

线程工作类

public class ClassThread

{

  //线程工作所需要的参数

  参数1

  参数2

  参数3

  public ClassThread(参数1,参数2, 参数3)

  {

    参数1 = 参数1;

    参数2 = 参数2;

    参数3 = 参数3;

  }

  public void ThreadThing()

  {

    try    //必须加try...catch...

    {

      //此处填写线程工作的内容

    }

    catch(Exception ex)

    {

    }

  }

}

//调用线程类

var threadList = new Thread[线程数];

foreach(var item in List<参数>)

{

  var threadIndex = SystemHelper.GetFreeThread(threadList);
  var Thread = new ClassThread(item);
  threadList[threadIndex] = new Thread(headerThread.ThreadThing);
  threadList[threadIndex].IsBackground = true;
  threadList[threadIndex].Start();

 }

SystemHelper.CheckThreadComplete(threadList);  //判断所有的线程是否已经完成

猜你喜欢

转载自www.cnblogs.com/MatrixBlogs/p/9122918.html