473,804 Members | 3,607 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

multithread to richtextbox

hello
i put a richtextbox and a button on the winForm.when the button is clicked,it generate several threads to write to the richtextbox,the code snippet as following:
private void btnSend_Click(o bject sender, System.EventArg s e)
{
for(int i=0;i<3;i++)
{
Thread thread =new Thread(new ThreadStart(rpt ));
thread.Start();
}
}

private void rpt()
{
this.richTextBo x1.AppendText(" hello world");
}
it throw null reference exception,i wonder how can i write to the richtextbox MULTITHREADINGL Y,any code snippet is appreciated.

thank you!

Nov 16 '05 #1
3 4066
By using Form.BeginInvok e.

Also in this case it could be an idea to read and understand the conceptual
foundation. The 3 series article on MSDN on multi threaded WindowsForms
programming could make a good beginning. When you've understood the concepts
you'll know that the richtextbox may only be used by the STA thread which
created it.
Best regards,

Henrik Dahl
"zbcong" <zb****@discuss ions.microsoft. com> wrote in message
news:79******** *************** ***********@mic rosoft.com...
hello
i put a richtextbox and a button on the winForm.when the button is clicked,it generate several threads to write to the richtextbox,the code
snippet as following:

private void btnSend_Click(o bject sender, System.EventArg s e)
{
for(int i=0;i<3;i++)
{
Thread thread =new Thread(new ThreadStart(rpt ));
thread.Start();
}
}

private void rpt()
{
this.richTextBo x1.AppendText(" hello world");
}
it throw null reference exception,i wonder how can i write to the richtextbox MULTITHREADINGL Y,any code snippet is appreciated.
thank you!

Nov 16 '05 #2
your code is perfect it will run perfectly..

but still try this

delegate void rptdel();

private void rpt()

{

for(int i=0;i<3000;i++)

{

this.richTextBo x1.AppendText(" hello world");

}

}

private void button2_Click(o bject sender, System.EventArg s e)

{rptdel rp = new rptdel(rpt);
rp.BeginInvoke( null,null);
}
"zbcong" <zb****@discuss ions.microsoft. com> wrote in message
news:D7******** *************** ***********@mic rosoft.com...
hello
i put a richtextbox and a button on the winForm.when the button is clicked,it generate several threads to write to the richtextbox,the code
snippet as following:

private void btnSend_Click(o bject sender, System.EventArg s e)
{
for(int i=0;i<3;i++)
{
Thread thread =new Thread(new ThreadStart(rpt ));
thread.Start();
}
}

private void rpt()
{
this.richTextBo x1.AppendText(" hello world");
}
it throw null reference exception,i wonder how can i write to the richtextbox MULTITHREADINGL Y,any code snippet is appreciated.
thank you!

"zbcong" <zb****@discuss ions.microsoft. com> wrote in message
news:79******** *************** ***********@mic rosoft.com... hello
i put a richtextbox and a button on the winForm.when the button is clicked,it generate several threads to write to the richtextbox,the code
snippet as following:

private void btnSend_Click(o bject sender, System.EventArg s e)
{
for(int i=0;i<3;i++)
{
Thread thread =new Thread(new ThreadStart(rpt ));
thread.Start();
}
}

private void rpt()
{
this.richTextBo x1.AppendText(" hello world");
}
it throw null reference exception,i wonder how can i write to the richtextbox MULTITHREADINGL Y,any code snippet is appreciated.
thank you!

Nov 16 '05 #3
You should also invoke EndInvoke().
Best regards,

Henrik Dahl

"Shaival Trivedi" <sh*****@gatewa ytechnolabs.com > wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
your code is perfect it will run perfectly..

but still try this

delegate void rptdel();

private void rpt()

{

for(int i=0;i<3000;i++)

{

this.richTextBo x1.AppendText(" hello world");

}

}

private void button2_Click(o bject sender, System.EventArg s e)

{rptdel rp = new rptdel(rpt);
rp.BeginInvoke( null,null);
}
"zbcong" <zb****@discuss ions.microsoft. com> wrote in message
news:D7******** *************** ***********@mic rosoft.com...
hello
i put a richtextbox and a button on the winForm.when the button is

clicked,it generate several threads to write to the richtextbox,the code
snippet as following:


private void btnSend_Click(o bject sender, System.EventArg s e)
{
for(int i=0;i<3;i++)
{
Thread thread =new Thread(new ThreadStart(rpt ));
thread.Start();
}
}

private void rpt()
{
this.richTextBo x1.AppendText(" hello world");
}
it throw null reference exception,i wonder how can i write to the

richtextbox MULTITHREADINGL Y,any code snippet is appreciated.

thank you!

"zbcong" <zb****@discuss ions.microsoft. com> wrote in message
news:79******** *************** ***********@mic rosoft.com...
hello
i put a richtextbox and a button on the winForm.when the button is

clicked,it generate several threads to write to the richtextbox,the code
snippet as following:


private void btnSend_Click(o bject sender, System.EventArg s e)
{
for(int i=0;i<3;i++)
{
Thread thread =new Thread(new ThreadStart(rpt ));
thread.Start();
}
}

private void rpt()
{
this.richTextBo x1.AppendText(" hello world");
}
it throw null reference exception,i wonder how can i write to the

richtextbox MULTITHREADINGL Y,any code snippet is appreciated.

thank you!


Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1619
by: Alice | last post by:
Hello I have four multithread windows applications(vb.net) interacting and running on the same machine(windows 2000 with .net framework 1.0). All of them start a new thread each time Filewatcher's created or deleted event is fired. One of these application writes data into word documents also in multithread fashion. Sometimes the created and the deleted events of FileWatcher are not fired in one application - not the same one each time. Any...
0
1868
by: r_obert | last post by:
Hello, I'm trying to create a worker thread for my VC++ program, and was wondering whether I should be linking with the Multithread /MT or Multithread DLL /MD option? I'm not quite sure, in layman's terms, what the difference is. When I build with Multithread DLL, the linker complains about not being able to find a bunch of "unresolved external symbols" associated with nafxcwd.lib.
4
7092
by: zbcong | last post by:
Hello: I write a multithread c# socket server,it is a winform application,there is a richtextbox control and button,when the button is click,the server begin to listen the socket port,waiting for a incoming connection,the relative code snipprt as following:: private IPAddress myIP=IPAddress.Parse("127.0.0.1"); private IPEndPoint myServer; private Socket socket; private Socket accSocket; private System.Windows.Forms.Button button2;...
2
26521
by: zhebincong | last post by:
Hello: I write a multithread c# socket server,it is a winform application,there is a richtextbox control and button,when the button is click,the server begin to listen the socket port,waiting for a incoming connection,the relative code snipprt as following:: private IPAddress myIP=IPAddress.Parse("127.0.0.1");
2
17389
by: JonnyT | last post by:
I searched high and low for an answer on how to auto scroll a richtextbox and now I finally have it. Since it took me a while to get a good efficient way of doing it that didn't require focus to the control or the scrolltocaret method I decided that it would be worth posting to anyone who might have similar concerns. For the record this works well in an environment where you cannot have focus going to the richtextbox....such as a chat...
0
1319
by: fred | last post by:
I need some help in trying to understand how to make myCollection (inherited from CollectionBase) multithread safe. Taking my implementation of the Add Sub and a readonly property Item. Public Sub Add(ByVal aDoc As myDocument) List.Add(aDoc) End Sub Can I make this multithread safe by and is this the best way to do it.
6
2825
by: jmartin | last post by:
Hi, I have made a multithread version of a program (load a file into database), and with two processors I get the double of time in the multithread than in the process (unithread) version. I have done the test of creating a unique thread that does the same code that the process version of the program and it takes more time that the process without creating the thread.
9
4881
by: James Wong | last post by:
Hi, I use the RichTextBox in my program. It will use different language in this RichTextBox (chinese and english characters), and it set the "DualFont" and use different fonts. By the way, how can I print out this content to printer easily? Thanks! James
0
2061
by: Vimalathithan | last post by:
I just developing a editor. I have provide the options like Bold, Italic, underlin, font change, font size change. These font options are keep in with one toolstripbutton. the toolstripbar keep inside with panel. The RichTextBox keep inside with other panel. The panel height and width is same with RichTextBox. The RichTextBox both scrolling options are make it as false. I done the coding for RichTextBox's height to fit with...
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10571
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9143
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6851
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5520
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4295
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2990
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.