ازاى استخدم threading مع progressbar
بتظهر لى هذه الرسالة
Cross-thread operation not valid: Control 'progressBar1' accessed from a thread other than the thread it was created on.
عند تنفيذ الكود التالى
[public void DoTh()
{
int step;
int val;
Random rnd = new Random();
while (true)
{
step = this.progressBarX.Step * rnd.Next(-1, 200);
val = this.progressBarX.Value + step;
if (val > this.progressBarX.Maximum)
val = this.progressBarX.Maximum;
else if (val < this.progressBarX.Minimum)
val = this.progressBarX.Minimum;
this.progressBarX.Value = val;
Thread.Sleep(50);
}
}
private void Form1_Load(object sender, EventArgs e)
{
Thread th = new Thread(new ThreadStart(DoTh));
th.IsBackground = true;
th.Start();
}
