Thread Headache

Aug 19 2007 7:36 PM
Ok so, the program I created needs to launch a variable amount of threads between 300-600 and be able to close individual threads/all threads at any time. Boolean checking is not an option - not all threads will close by the time new threads start and the program will not function. I'm looking for a way to give each thread an id and store it in an array parallel to variables_to_monitor so that the indexes match up and can be used to look up the id based on the index and terminate. Any ideas/help would be wonderful!!

private bool[] = new bool[0x301];
private Thread ThrScanner;
private int[] variables_to_monitor;
private int argument_to_pass;
private void timer1_Tick(object sender, EventArgs e)
{
for (int i = 0; i <= 0x300; i++)
{
if (variables_to_monitor[ i ] != 0 & !bool[ i ])
{
bool[ i ] = true;
arguement_to_pass = i;
ThrScanner = new Thread(Monitor);
ThrScanner.IsBackground = true;
ThrScanner.Start();
}
}
}

private void Monitor();
{
while (true)
{
int compare_variables = variables_to_monitor[arguement_to_pass];
while(compare_variables == variables_to_monitor)
{ System.Threading.Thread.Sleep(10); }
// variables changed, event triggered
}
}

private void button_Click(object sender, System.EventArgs e)
{
ThrScanner.Abort();
bool[] = new bool[0x301];
ThrScanner.Join();
}

Answers (2)