0

I have a readstream opened in a form. I'm reading from that stream and sending text to another form's textbox . i want the text to be updated to the textbox as soon the text arrives in readstream.
code in first form:->

 f2.ShowDialog(); //f2 is second form's object
 while (true)
 {
    string inp_msg = sr.ReadLine();

    f2.set_text(inp_msg);
    this.Refresh();              
 }

set_text function defined in second form:->

 public void set_text(string msg)
 {
    //MessageBox.Show(msg);            
    textBox1.Text = textBox1.Text + msg +  "\r\n";
    //Application.DoEvents();
 }

the problem is that the textbox is not updating .

Rohit Vats
  • 79,502
  • 12
  • 161
  • 185

1 Answers1

0

Instead of 'f2.ShowDialog()', try calling:

f2.Show();

When you call the method 'ShowDialog()', the code after that statement isn't executed until the form is closed.

See http://msdn.microsoft.com/en-us/library/c7ykbedk.aspx for more details.

Rohan
  • 359
  • 2
  • 16
  • i've tried this but the program hangs and shows "not responding" dialog box – algorithmist Aug 18 '13 at 06:18
  • As King King commented, you're running in an infinite loop. You need a break; statement to stop the while loop from looping over and over again. – Rohan Aug 18 '13 at 06:19