I have a c# windows form app. Right now it works fine alone in single thread. Here is how I launch it in a click on button.
botThread = new Thread(new ThreadStart(mainThread));
botThread.Start();
So one thread gets launched.
The user will specify the number of threads to run at a time in a text box as number. So I want that many threads to get launched and each thread should get a line from a text file. so if the thread is first, it should get the first line of a text file.
If a user specified two threads, once the first instance of thread ends doing the job or it had any expection, i want the bot to move to the next instance and start a new thread with the 3rd line of text file.
I am not sure what to do. I tried using for loop but i couldn't keep track of the threads and couldn't launch new ones when one ends
edit : Here is for loop code :
int j = int.Parse(settings_textbox_instances.Text);
for (i = 0; i < j; i++)
{
botThread = new Thread(new ThreadStart(mainThread));
botThread.Start();
}
edit 1 :
I have worked with the code and made this.
private void multiThreader(int instances)
{
for (i = 0; i < instances; i++)
{
botThread = new Thread(new ThreadStart(mainThread));
string text = this.users_List[this.i];
botThread.Start();
threadcount++;
MessageBox.Show(i.ToString());
}
}
so when ending the thread i can call the void in to create new instances. But can anyone say to me on how i can transfer the value of text from here to the thread ?