熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

使用ThreadStart委托來衍生三個新線程

2022-06-13   來源: .NET編程 

  //使用ThreadStart委托來衍生三個新線程

  using System;

  using SystemThreading;

  namespace ThreadStartSampleCS

  {

  class Program

  {

  static void Main()

  {

  Thread newThread;

  ThreadStart threadMethod = new ThreadStart(DoWork);

  for (int counter = ; counter < ; counter++)

  {

  ConsoleWriteLine(Starting Thread {} counter);

  newThread = new Thread(threadMethod);

  newThreadName = counterToString();

  newThreadStart();

  }

  ConsoleReadLine();

  }

  static void DoWork()

  {

  for (int counter = ; counter < ; counter++)

  {

  ConsoleWriteLine(Thread {}: iteration {} ThreadCurrentThreadName counter);

  ThreadSleep();

  }

  }

  }

  }


From:http://tw.wingwit.com/Article/program/net/201311/11465.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.