ThreadManager

たくさんのスレッドを管理するのに便利なので公開
実装はC#だがdllにしたのでC++VBなどでも使える

http://shokai.org/projects/threadmanager/

using Org.Shokai.Util.Thread;
ThreadManager thManager = new ThreadManager(10); // 10個管理する


スレッド登録と実行

int th_id;

Thread th = new Thread(delegate()
{
  while (!thManager.isCallingStop(thread_id)) // 止めろと言われてないかチェック
  {
    // なんか処理
    // なんか処理
    Thread.Sleep(1000); // stop 1.0sec
  }
  thManager.Stopped(thread_id); // 止めましたと報告
});

th_id = thManager.Register(th);
th.Start();

停止

thManager.Stop(th_id);

もしくは、全登録スレッド停止

thManager.StopAllThreads();

全スレッド停止の場合は、int th_idなども管理しなくて良いので楽。


5個スレッド個別管理してみた
thread manager - 5 threads


1000個もいけた(画面表示の方が追いつかない)
thread manager - 1000 threads