Click here to Skip to main content
16,019,199 members

Comments by Member 8041630 (Top 1 by date)

Member 8041630 26-Sep-12 4:57am View    
Hi,
I am creating an windows based application which download the data from server.
I am using the background thread which is created on different class to perform these download operation.And I want to continuously show the download status on rich textbox i.e on main thread.But i am unable to do this,get an Cross-thread operation not valid.
Please help me to resolve this problem.


method on Form1.cs

public void UpdateRichText(string Text)
{
SetRichText(Text);
}

public delegate void SetRichTextTextDelegate(string text);
public void SetRichText(object number)
{
if (InvokeRequired)
{
this.BeginInvoke(new SetRichTextTextDelegate(SetRichText), text);
return;
}

richTextBox1.Text += number.ToString() + "\n";
}
private void button3_Click_1(object sender, EventArgs e)
{
demo d = new demo();
d.display();
}

methods on demo.cs

Form1 f = new Form1();
public void display()
{
Thread t = new Thread(new ThreadStart(call));
t.Start();
}


public void call()
{
//when i call this method every time if(InvokeRequired) is false.
f.UpdateRichText("Called from Thread");
}