线程实现

Posted matrixblogs

tags:

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

线程工作类

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);  //判断所有的线程是否已经完成





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