Hello I am building a C# application and I have few questions regarding threads.
First of all I want to open threads in functions that has some arguments. I have the following code for example:
Thread GetStaff= new Thread(() => GetStaff(arg1));
GetStaff.Name = "Get Staff";
GetStaff.Start();
main_threads.Add(GetStaff);
Is the above code the best I can use to open a thread? Also the GetStaff.Name
is always right to using it to assign a name to my thread?
The main_threads in the above code is just a simple list. It is ok to have all the threads saved in a list and list them using this? Or its better to have dynamic code to list the threads?
I use the following code to close the threads:
foreach (Thread thread_work in main_threads)
{
if (thread_work.IsAlive)
{
thread_work.Abort();
thread_work.Join();
}
}
main_threads.Clear();
Any improvements?