الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

implement threading with progressbar

بدأه exlereo في 8 مايو 2010 · 2 رد · 909 مشاهدة · في Microsoft Visual C#.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

ازاى استخدم 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();

}

#2

يمكنك مراجعة هذا الموضوع فى قسم الـVB.NET

/index.php?showtopic=213882&st=0

إن قلت قال الله قال رسولـه همزوك همز المنكر المتعالي
أو قلت قد قال الصحابة والألـى تبعاً لهم بالقول والأعمال
أو قلت قـال الشافعي وأحمد و أبو حنيفة والإمام الغالي
صدوا عن وحي الإله ودينـه واحتالوا على حرام الله بالإحلال
يا أمةً لعبت بدين نبيها كتلاعب الصبيان في الأوحال
حاشا رسول الله يحكم بالهوى تلك إذاً حكومة الضلال

feed.1.gif

#3
public delegate void OnIncProgress(int val);

public void DoTh()
{
	IncProgress(0);
}

void IncProgress(int val)
{
	if(this.InvokeRequired)
	{
		this.Invoke(new OnIncProgress(IncProgress), new object[] { val });
		return;
	}
	int step;
	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();
}

مواضيع متنوعة

مواضيع مشابهة