I need to preform a time intensive task on two-four different servers.
The number of servers can vary.
I need to preform the same task on each machine at roughly the same time otherwise it quadruples the time this process takes.
So far I've been able to come up with this:
public partial class Form_main : Form
{
list<string> vms = new list<string>;
///Fill in vms...
private void startTest()
{
///prevents GUI from hanging
ThreadPool.QueueUserWorkItem(new WaitCallback(runTests));
}
pirvate void runTests()
{
///Some setup stuff (~1 min)
foreach(string vm in vms)
{
ThreadPool.QueueUserWorkItem(new WaitCallback(testProcedure), new object[] {vm});
}
}
}
This works for running everything at once but the problem is that if the GUI is killed the threads do not get killed along with it. I imagine that it is killing the runTests thread but is not killing the testProcedures threads.
How can I make it so that the testProcedures threads get killed on the closing of the GUI?