//控件界面刷新
private delegate void DelegateSetText(Control control, string text);
/// <summary>
/// 刷新控件
/// </summary>
/// <param name="control"></param>
/// <param name="text"></param>
private void SetText(Control control, string text)
{
try
{
if (control.InvokeRequired)
{
while (!control.IsHandleCreated) { }
DelegateSetText d = new DelegateSetText(SetText);
if (control.IsHandleCreated)
{
control.Invoke(d, new object[] { control, text });
}
}
else
{
if (control.IsHandleCreated)
{
control.Text = text;
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
以上为刷新控件委托及方法。。我的程序为一个MDI,对应每个子窗体开启后,都会开一个timer线程调用该方法,每个子窗体数据均正常的刷新 。。
异常出现在我关闭子窗体时。。会报 “在创建窗口句柄之前,不能在控件上调用Invoke或BeginInvoke”的错误。这种情况只是偶尔会出现。请问大家我如何处理
private delegate void DelegateSetText(Control control, string text);
/// <summary>
/// 刷新控件
/// </summary>
/// <param name="control"></param>
/// <param name="text"></param>
private void SetText(Control control, string text)
{
try
{
if (control.InvokeRequired)
{
while (!control.IsHandleCreated) { }
DelegateSetText d = new DelegateSetText(SetText);
if (control.IsHandleCreated)
{
control.Invoke(d, new object[] { control, text });
}
}
else
{
if (control.IsHandleCreated)
{
control.Text = text;
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
以上为刷新控件委托及方法。。我的程序为一个MDI,对应每个子窗体开启后,都会开一个timer线程调用该方法,每个子窗体数据均正常的刷新 。。
异常出现在我关闭子窗体时。。会报 “在创建窗口句柄之前,不能在控件上调用Invoke或BeginInvoke”的错误。这种情况只是偶尔会出现。请问大家我如何处理
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货