Cześć, mam mały problem, otóż na początku programu (Load mojej formy) muszę załadować dosyć sporo obrazków (koło 180) i trwa to parę sekund, chciałbym aby wywoływało się to w równoległym wątku, aby nie było "laga" aplikacji (tym bardziej, że obrazki są w drugiej zakładce i po starcie programu najpierw trzeba zrobić jakąś operację, aby przejść do nich). Nie wiem jak to ugryźć, nigdy takiego czegoś nie pisałem, oto kod:
private void LoadPicturesColors()
{
string exePath = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase;
string dir = System.IO.Path.GetDirectoryName(exePath);
string colorsDir = System.IO.Path.Combine(dir, "Colors");
string[] pngFiles = System.IO.Directory.GetFiles(new Uri(colorsDir).LocalPath, "*.png");
FileInfo imageInfo;
for (int i = 0; i < pngFiles.Length; i++)
{
this.pictureBoxColors.Add(new PictureBox());
this.pictureBoxColors[i].SizeMode = PictureBoxSizeMode.Zoom;
this.pictureBoxColors[i].Size = new Size(150, 150);
this.pictureBoxColors[i].Image = Image.FromFile(pngFiles[i]);
this.pictureBoxColors[i].Location = new Point(CalculateImageColorWidth(), CalculateImageColorHeight());
imageInfo = new FileInfo(pngFiles[i]);
this.pictureBoxColors[i].Name = imageInfo.Name.Remove(imageInfo.Name.Length - 4);
this.pictureBoxColors[i].Click += new EventHandler(this.pictureBoxColors_Click);
this.tabPageColor.Controls.Add(this.pictureBoxColors[i]);
this.radioButtonColors.Add(new RadioButton());
this.radioButtonColors[i].AutoSize = true;
this.radioButtonColors[i].TabIndex = i;
this.radioButtonColors[i].Name = this.pictureBoxColors[i].Name;
this.radioButtonColors[i].Location = new Point(CalculateImageColorWidth() + 75, CalculateImageColorHeight() + 150);
this.tabPageColor.Controls.Add(this.radioButtonColors[i]);
}
}