Using RichTextBox in a thread?

M

M O J O

Hi,

If I inside a thread creates a RichTextBox and only use this inside the
thread, will there be any thread problems?

I need to convert between Text and RTF inside a thread.

Thanks!!

M O J O
 
H

Herfried K. Wagner [MVP]

* M O J O said:
If I inside a thread creates a RichTextBox and only use this inside
the thread, will there be any thread problems?

I need to convert between Text and RTF inside a thread.

I don't think so.
 
M

Miha Markic

Hi,

Because UI control shouldn't be touched from within non-UI thread.
I am not 100% sure in your case though.
Let us know if you manage to use it.
 
P

Peter Huang

Hi Mojo,

Thanks for posting in the community. My name is Peter, and I will be
assisting you on this issue.

First of all, I would like to confirm my understanding of your issue.
From your description, I understand that you wants to use the RichTextBox
in a non-UI thread.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

I am researching the issue, if I have any new information, I will update
with you ASAP.

Have a nice day!


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

M O J O

Thank you all for your input.

I'm still not sure that using a RichTextBox created in a thread is un/safe.

Maybe Microsoft can give me some feedback here (Ray?)???

Thanks again!!!

M O J O
 
P

Peter Huang

Hi Mojo,

Based on my researching, I wants to confirm with you that
1. WinForm controls are not thread-safe, that is to say, you can not use
the controls in another thread if you create the controls in the Main
Thread.
If you wants to call the RichTextBox in the Main UI thread, you may need to
use the marshal the call back using Invoke or BegineInvoke.

Visual C# Windows Form Asynchronous Example
http://www.dotnetfun.com/Examples/WindowsForms/AsynchronousExample.aspx

2. Also there is more going on than just messages (API calls, etc) within
Windows Forms so you can't rely on Windows doing the marshalling. You can
have a separate form on a separate thread, but each thread needs to have
it's own message pump, etc.

Multithreaded Windows Forms Control Sample
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconDevelopingMultithreadedWindowsFormsControl.asp

If you have concern on this issue ,please post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Peter Huang

Hi Mojo,

It seems that you post some issues in the newsgroup about richtextbox. So I
wants to confirm with you if you will show the richtextbox in the new
created thread, just as you create the richtextbox in main UI thread.

Or will you show the richtextbox in the Main UI thread?

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

M O J O

Hi Peter,

Thank you for helping me out here!!!

I'm not going to show the RichTextBox in any threads.

I want to create a new RichTextBox in a seperate thread (not the main
thread) and do some text/rtf conversions and the tell the mainform the
RichTextBox.RTF text.

So I'm not going to show the RichTextBox in any threads only use it to
create som RTF, which I will send to the main form.

Best regards,
M O J O
 
P

Peter Huang

Hi Mojo,

So far I am understanding what you wants to do is to use the RTF and Text
properties of RichTextBox based on test, this will work in a new create
thread. I am not sure if you will do other operation on the RichTextBox.

Although we did not suggest you use a Winform Control in a non-GUI thread.
Anyway, if you have any concern on this issue, please post here, I am glad
to help you.


Regards,
Peter Huang

This posting is provided "AS IS" with no warranties, and confers no rights.
 

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