This is the code to start all the threads for my checker:
Code:
public void Run()
{
Task.Run(() =>
{
this.Invoke(new MethodInvoker(delegate ()
{
bStart.Enabled = false;
}));
for (int i = 1; GlobalVariables.ThreadCount > i; i++)
{
Thread T = new Thread(DoWork)
{
IsBackground = true
};
GlobalVariables.TList.Add(T);
GlobalVariables.TList[i-1].Start();
Thread.Sleep(20);
}
this.Invoke(new MethodInvoker(delegate ()
{
bStart.Enabled = true;
}));
});
}
This is the code to abort all the threads and stop the checker:
Code:
private void Stop()
{
GlobalVariables.Running = false;
foreach (Thread T in GlobalVariables.TList)
{
T.Abort();
}
foreach (string Combo in GlobalVariables.TempQueue)
{
GlobalVariables.ComboQueue.Enqueue(Combo);
}
GlobalVariables.TempQueue.Clear();
GlobalVariables.TList.Clear();
}
The code to start all the threads works fine, however when I want to stop the checker, it freezes the UI and sometimes throws errors. Can someone show me a more efficient way of doing this please?