multi-thread update to RichTextBox

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
 
T

Trecius

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
 
P

Pavel Minaev

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
 
C

Cor Ligthert[MVP]

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
 
C

Cor Ligthert[MVP]

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
 
C

Cor Ligthert[MVP]

duh,

In my idea it is never correct to access an UI correct = direct

Cor
 
C

Cor Ligthert[MVP]

duh,

In my idea it is never correct to access an UI correct = direct

Cor
 
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

Setting CheckForIllegalCrossThreadCalls = false; fixes the problem
thanks! I haven't experienced any kind of problems yet using this
method.
 
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

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top