我正在显示动画,而我的控件正在加载数据。当线程完成时,我隐藏动画并显示控件。所以我从一个线程执行这段代码:
protected void InvokeEnableBackControl()
{
if (this.InvokeRequired)
{
this.Invoke(new OpHandler(EnableBackControl));
}
else
{
EnableBackControl();
}
}
有时,当我执行这段代码时,主线程会在以下代码中挂起:
protected virtual void EnableBackControl()
{
if (overlayAnimation.TargetControl != null)
{
overlayAnimation.TargetControl.BringToFront();
}
overlayAnimation.SendToBack();
overlayAnimation.Enabled = false;
overlayAnimation.Visible = false;
我不确定设置 Enable
或 Visible
属性是否挂起。您是否知道任何可能使应用程序从 Control.Invoke
调用这些属性的情况?
最佳答案
请注意 Control.Invoke
是同步的,因此它将等待 EnableBackControl()
返回。考虑使用 Control.BeginInvoke
,您可以“触发后忘记”。
查看此答案:What's the difference between Invoke() and BeginInvoke()
关于c# - Control.Invoke() 挂起应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5119263/