I have a program which has multiple threads. User can choose amount of threads to be chosen and that is handled as such:
for (int i = 0; i <= form.Bots - 1; i++)
{
(new Thread(() => {
doThreadWork();
form.Console = "Thread(" + Thread.CurrentThread.ManagedThreadId + ") FINISHED " + usedCombos.Count + "/" + form.Combolist.Count;
})).Start();
}
doThreadWork is a method each thread has to complete before shutting down. I have an arraylist, which consists of multiple items (lines).
Ex.
value:value
value1:value1
value2:value2
value11:value11
value4:value4
value13:value13
Now the threads exist in my program to make the process of handling these values faster. The program checks which value is valid and which is not. Currently I have implemented a (horrible?) method of choosing the value to be checked for the thread.
int index = GetRandomNumber(0, form.Combolist.Count);
That gets an random index to be chosen in the list. I implemented this because otherwise if I just used a foreach loop, every thread would be checking same value at same time. I need to get something like such:
Imagine following as console logs. Each thread is running at the same time. Values total count is 12. Threads running is 4.
Thread 1: checking index 1
Thread 2: checking index 2
Thread 3: checking index 3
Thread 4: checking index 4
Thread 1: checking index 5
Thread 2: checking index 6
Thread 3: checking index 7
Thread 4: checking index 8
Thread 1: checking index 9
Thread 2: checking index 10
Thread 3: checking index 11
Thread 4: checking index 12
Thread 1: FINISHED
Thread 2: FINISHED
Thread 3: FINISHED
Thread 4: FINISHED
I really hope some of you advanced people could help me out with this, I'm not that advanced :)