You need to do the work in multiple threads. Try the following:
class Program { static bool isRunning = true; static void Main(string[] args) { BackgroundWorker bw1 = new BackgroundWorker(); BackgroundWorker bw2 = new BackgroundWorker(); bw1.DoWork += delegate(object sender, DoWorkEventArgs e) { while (isRunning) { } }; bw2.DoWork += delegate(object sender, DoWorkEventArgs e) { while (isRunning) { } }; bw1.RunWorkerAsync(); bw2.RunWorkerAsync(); Console.ReadLine(); isRunning = false; } }
You can increase the number of background workers depending on how many cores you have (this example extends my dual-core computer). You can put your code after running workers, and then stop them by changing the isRunning value.
source share