/// <summary> /// Main form /// </summary> public MainForm() { InitializeComponent(); MaterialSkinManager material_skin_manager = MaterialSkinManager.Instance; material_skin_manager.AddFormToManage(this); material_skin_manager.Theme = MaterialSkinManager.Themes.DARK; material_skin_manager.ColorScheme = new ColorScheme(Primary.Blue700, Primary.Blue800, Primary.Blue500, Accent.LightBlue200, TextShade.WHITE); threadPool = new CountableThreadPool(Environment.ProcessorCount - (Environment.ProcessorCount / 4)); }
/// <summary> /// Number of threads /// </summary> /// <param name="numOfThreads">Number of threads (smaller or equal 0 uses the processor count)</param> public CountableThreadPool(int numOfThreads = 0) { threads = new ParameterizedThread[(numOfThreads > 0) ? numOfThreads : Environment.ProcessorCount]; observerThread = new Thread(new ParameterizedThreadStart((instance) => { if (instance is CountableThreadPool) { CountableThreadPool that = (CountableThreadPool)instance; while (observerRunning) { lock (threads) { for (int i = 0; i < threads.Length; i++) { ParameterizedThread thread = threads[i]; if (thread == null) { that.AssignWork(i); } else { if (thread.Thread.ThreadState != ThreadState.Running) { try { thread.Thread.Join(); } catch (Exception e) { Console.Error.WriteLine(e.Message); } threads[i] = null; that.AssignWork(i); } } } } Thread.Sleep(observerSleepTime); } } })); observerThread.Start(this); }