In my program I read several information's about the system. I read each categories like CPU, memory, services, software and so on with a own thread. The main program have to wait for the longest thread.
To implement this, I use LINQ and the Join function from Thread.
Here is a small part from my code:
var culture = CultureInfo.CreateSpecificCulture("en-US");
var thread_list = new List<Thread>();
var c = new Computer();
var thrma = new Thread(() =>
{
c.Mainboard = new Mainboard().GetInformation();
});
thrma.CurrentUICulture = culture;
thrma.Start();
thread_list.Add(thrma);
var thrce = new Thread(() =>
{
c.ProcessorList = new CentralProcessingUnit().GetInformation();
});
thrce.CurrentUICulture = culture;
thrce.Start();
thread_list.Add(thrce);
...
var thrsvr = new Thread(() =>
{
DeviceService.ScanServices();
});
thrsvr.CurrentUICulture = culture;
thrsvr.Start();
thread_list.Add(thrsvr);
foreach (Thread t in thread_list)
{
t.Join();
}
// Everyone is done!
Each hardware device is derived from the Hardware class.
What do you think about the solution? Is there a "nicer" or better implementation? I would like to use a function, because the code is very similar, but I'm not sure how to do it. Any idea?
Thanks for your advices.
Mainboard,CentralProcessingUnitandDeviceServiceclasses written by you or came from 3rd-party library? \$\endgroup\$