我是多线程的新手。我的计算机上有 4 个逻辑进程,我想在 4 个不同内核上的线程中运行 4 个相同的任务。我该怎么做?我尝试使用BackgroundWorker
但 4 个 BackgroundWorker 实例仅填充 2 个可用的 4 个内核。我的带有 BackgroundWorker 的代码示例:
BackgroundWorker worker = new BackgroundWorker();
worker.DoWork += new DoWorkEventHandler(worker_DoWork);
worker.RunWorkerAsync(calculationParams);
BackgroundWorker worker1 = new BackgroundWorker();
worker1.DoWork += new DoWorkEventHandler(worker_DoWork);
worker1.RunWorkerAsync(calculationParams1);
BackgroundWorker worker2 = new BackgroundWorker();
worker2.DoWork += new DoWorkEventHandler(worker_DoWork);
worker2.RunWorkerAsync(calculationParams2);
BackgroundWorker worker3 = new BackgroundWorker();
worker3.DoWork += new DoWorkEventHandler(worker_DoWork);
worker3.RunWorkerAsync(calculationParams3);