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

سؤال عن ال Threading

مغلق
بدأه FerasGer83 في 6 فبراير 2006 · 7 رد · 788 مشاهدة · في Microsoft Visual C#.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ....

لدي مشكلة صغيرة متعلقة بالـ Threading ...

قمت بعمل Thread لتعديل قيمة richTextBox و لكنه عند تغيير قيمة الـ richTextBox يطلق رسالة خطأ تقول أن الـ Thread الذي أنشأ الـ richTextBox هو غير الـ Thread الذي يقوم بتغيير قيمته .... و هو ما سماه Cross-Thread Operations ...

WindowsApplication1.zip

#2

سأكتب موضوعاً الليلة في الThreading يتعلق بهذه المشكلة بالتحديد...

Sr. Software Development Engineer
Hulu, LLC
My Blogs

#3

شكراً لك أخي .... بإنتظار المشاركة ....

#4

نقلا من MSDN:

Access to Windows Forms controls is not inherently thread safe. If you have two or more threads manipulating the state of a control, it is possible to force the control into an inconsistent state. Other thread-related bugs are possible as well, including race conditions and deadlocks. It is important to ensure that access to your controls is done in a thread-safe way.

To make a thread-safe call a Windows Forms control

1-Query the control's InvokeRequired property

2-If InvokeRequired returns true, call Invoke with a delegate that makes the actual call to the control.

3-If InvokeRequired returns false, call the control directly.

// This event handler creates a thread that calls a 
// Windows Forms control in a thread-safe way.
private void setTextSafeBtn_Click(
    object sender, 
    EventArgs e)
{
    this.demoThread = 
        new Thread(new ThreadStart(this.ThreadProcSafe));

    this.demoThread.Start();
}

// This method is executed on the worker thread and makes
// a thread-safe call on the TextBox control.
private void ThreadProcSafe()
{
    this.SetText("This text was set safely.");
}
// This method demonstrates a pattern for making thread-safe
// calls on a Windows Forms control. 
//
// If the calling thread is different from the thread that
// created the TextBox control, this method creates a
// SetTextCallback and calls itself asynchronously using the
// Invoke method.
//
// If the calling thread is the same as the thread that created
// the TextBox control, the Text property is set directly. 

private void SetText(string text)
{
    // InvokeRequired required compares the thread ID of the
    // calling thread to the thread ID of the creating thread.
    // If these threads are different, it returns true.
    if (this.textBox1.InvokeRequired)
    {    
        SetTextCallback d = new SetTextCallback(SetText);
        this.Invoke(d, new object[] { text });
    }
    else
    {
        this.textBox1.Text = text;
    }
}

المقال كاملا

#5

ِشكراً جزيلاً للاخ باشمهندس و الأخ محمد عادل .... بالفعل إنحلت المشكلة تماماً .... الله يعطيكن العافية ...

بحب أضيف مما قرأت بالمقالة اللي وضعها الأخ محمد عادل أنو يمكن العمل كما في Visual Studio 2003 بوضع الخاصية System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls على القيمة false ....

#6

بصوا ..لو جينا نبحث بالعربى عن CheckForIllegalCrossThreadCalls

مش هنلاقى غير المشاركات اللى انتوا كتبتوها هنا فى الموضوع ده

13702902.jpg

#7

مش حتلاقيها غير في هذا الموضوع لانه كتابتها غلط :D

اعمل بحث على CheckForIllegalCrossThreadCalls ستجد الملايين من الصفحات

أما CheckForlllegalCrossThreadCalls فانك لن تجد سوى هذه الصفحة :P

انتبه على الفرق بين حرف ال l وحرف الآي l ;)

#8

فى حاجه غريبه بتحصل لو عملناstrart with out debugging

موش حيطلع الاكسبشن

ولو عملنا debugging

حيطلع الاكسبشن *-)

هذا الموضوع مغلق.

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