Help: BeginInvoke problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In the form cs:
form()
{
Thisfrm = this;
}
....
....
public delegate void delegateWriteDetail (string str);
private void WriteDetailScreen(string str)
{
delegateWriteDetail updateDelegate = new delegateWriteDetail (WriteDetail );
Thisfrm.BeginInvoke (updateDelegate, new object[] {str});
}

private void WriteDetail (string str)
{
this.txtDetail.Text = str + "\r\n" + this.txtDetail.Text;
}

When I call WriteDetailScreen method that will call BeginInvoke method to let the UI thread update the screen. Something, the WriteDetailScreen method may be called by the same UI thread for the form or called by other threads. When the program is running, the screen is updated properly but I find that I sometime get the error message when call the WriteDetailScreen method. The error is below:
"Invoke or BeginInvoke cannot be called on a control until the window handle has been created"

Why?
How to solve it?
 
In the form cs:
form()
{
Thisfrm = this;
}
...
...
public delegate void delegateWriteDetail (string str);
private void WriteDetailScreen(string str)
{
delegateWriteDetail updateDelegate = new delegateWriteDetail (WriteDetail );
Thisfrm.BeginInvoke (updateDelegate, new object[] {str});
}

private void WriteDetail (string str)
{
this.txtDetail.Text = str + "\r\n" + this.txtDetail.Text;
}

When I call WriteDetailScreen method that will call BeginInvoke
method to let the UI thread update the screen. Something, the
WriteDetailScreen method may be called by the same UI thread for the
form or called by other threads. When the program is running, the
screen is updated properly but I find that I sometime get the error
message when call the WriteDetailScreen method. The error is below:
"Invoke or BeginInvoke cannot be called on a control until the window
handle has been created"

That suggests that something is calling WriteDetailScreen before the
form has first been displayed. It's hard to say for sure without a
short but complete program though.

(Just a tiny point - it's worth following the naming conventions at
http://tinyurl.com/2cun - it'll be easier for others to follow your
code if they can immediately guess if something is a type etc by its
capitalization.)
 
Back
Top