BeginInvoke ile Asenkron Konrol Ekleme
4 Mayıs Pazartesi, 2009 | C# /*Yorumlar (1)*/
CheckForIllegalCrossThreadCalls = false; ve Thread güvenliği can sıkıcı olursa;
using System.Threading;
using System.IO;
namespace desktop
{
public partial class Form1 : Form
{
public delegate void Ekle();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
flowLayoutPanel1.BeginInvoke(new Ekle(ResimEkle));
}
void ResimEkle()
{
foreach (string file in Directory.GetFiles(@"D:\Pictures\aniGifs", "*.gif"))
{
PictureBox p = new PictureBox();
p.Width = 50;
p.Height = 50;
p.SizeMode = PictureBoxSizeMode.StretchImage;
p.ImageLocation = file;
flowLayoutPanel1.Controls.Add(p);
}
}