multi-thread update to RichTextBox

  • Thread starter Thread starter orellana
  • Start date Start date
O

orellana

I have a RichTextBox that I'm trying to change based on incoming
packets from the network. I get the following error when the
RichTextBox is changed inside my server thread:
"An unhandled exception of type 'System.InvalidOperationException'
occurred in System.Windows.Forms.dll
Additional information: Cross-thread operation not valid: Control
'CapturedBox' accessed from a thread other than the thread it was
created on."

I understand the error message. It happens inside my thread that
captures all requests from clients (UDP). Is there a quick and easy
way to get around it?

Thanks
 
A quick, easy -- but not recommended -- way to handle this is to set your
program to allow cross-thread changes...

CheckForIllegalCrossThreadCalls = false;

That should do it, but I would look into the property... InvokeRequired. If
this property is true, you can then just call Invoke(...).

I hope this helps you in your task.


Trecius
 
I have a RichTextBox that I'm trying to change based on incoming
packets from the network. I get the following error when the
RichTextBox is changed inside my server thread:
"An unhandled exception of type 'System.InvalidOperationException'
occurred in System.Windows.Forms.dll
Additional information: Cross-thread operation not valid: Control
'CapturedBox' accessed from a thread other than the thread it was
created on."

I understand the error message. It happens inside my thread that
captures all requests from clients (UDP).  Is there a quick and easy
way to get around it?

Control.Invoke
 
Orellana,

In my idea it is never correct to access an UI correct, access a control
direct is even worse.

Why I write this? Simple try to change your source to something else and
bind the richtextbox to that.

Cor
 
Orellana,

In my idea it is never correct to access an UI correct, access a control
direct is even worse.

Why I write this? Simple try to change your source to something else and
bind the richtextbox to that.

Cor
 
I have a RichTextBox that I'm trying to change based on incoming
packets from the network. I get the following error when the
RichTextBox is changed inside my server thread:
"An unhandled exception of type 'System.InvalidOperationException'
occurred in System.Windows.Forms.dll
Additional information: Cross-thread operation not valid: Control
'CapturedBox' accessed from a thread other than the thread it was
created on."

I understand the error message. It happens inside my thread that
captures all requests from clients (UDP).  Is there a quick and easy
way to get around it?

Thanks

Setting CheckForIllegalCrossThreadCalls = false; fixes the problem
thanks! I haven't experienced any kind of problems yet using this
method.
 
I have a RichTextBox that I'm trying to change based on incoming
packets from the network. I get the following error when the
RichTextBox is changed inside my server thread:
"An unhandled exception of type 'System.InvalidOperationException'
occurred in System.Windows.Forms.dll
Additional information: Cross-thread operation not valid: Control
'CapturedBox' accessed from a thread other than the thread it was
created on."

I understand the error message. It happens inside my thread that
captures all requests from clients (UDP).  Is there a quick and easy
way to get around it?

Thanks

Setting CheckForIllegalCrossThreadCalls = false; fixes the problem
thanks! I haven't experienced any kind of problems yet using this
method.
 
Back
Top