I am creating an instance of a class that is in DLL and can't be modified. It loads images and it takes long time which freezes the WinForms UI.
Can I instantiate the class on a new thread?
var images = new AppImages(); // This to execute on new thread?
var cboData = new List<string>();
foreach(var image in images)
{
cboData.Add(image);
}
comboBox.DataSource = cboData;
I am trying to use
private void My()
{
var images = ThreadPool.QueueUserWorkItem(GetAppImages);
var cboData = new List<string>();
foreach(var image in images)
{
cboData.Add(image);
}
comboBox.DataSource = cboData;
}
private AppImages GetAppImages()
{
return new AppImages();
}
but the threadPool doesn't return any value, it is just executing the code and I need the new instance to work with it later in the code.
Also, I can call the entire logic in a new thread because there are UI elements (the comboBox for example).