在下面的方法中,UI线程偶尔挂在语句'if (this.InvokeRequired)'上。
你能帮我找出问题的原因吗?
public void OnModuleInitializationCompleted(object sender, EventArgs e)
{
ModuleStatusWindow.Logger.LogMessage("OnModuleInitializationCompleted", LogMessageType.Information, "Received {0}", (sender as IModule).Name);
if (this.InvokeRequired)
{
this.BeginInvoke(new ECEventsHandler(OnModuleInitializationCompleted), sender, e);
}
else
{
CheckIfAllModulesInitComplete();
}
}
private void CheckIfAllModulesInitComplete()
{
ModuleStatusWindow.Logger.LogMessage("CheckIfAllModulesInitComplete", LogMessageType.Information, "Enter >>");
this._moduleStatusGrid.DataSource = this._moduleDataList.ToArray();
this._moduleStatusGrid.Invalidate();
ModuleStatusWindow.Logger.LogMessage("CheckIfAllModulesInitComplete", LogMessageType.Information, "Updated grid control...");
if (this._moduleDataList.Count(moduleData => !moduleData.IsInitOver) == 0)
{
this._footprint.DeActivate();
ModuleStatusWindow.Logger.LogMessage("CheckIfAllModulesInitComplete", LogMessageType.Information, "Stopping message listenr...");
ClientMessageListner.Stop();
ModuleStatusWindow.Logger.LogMessage("CheckIfAllModulesInitComplete", LogMessageType.Information, "Closing Window...");
this.Close();
}
ModuleStatusWindow.Logger.LogMessage("CheckIfAllModulesInitComplete", LogMessageType.Information, "Leave <<");
}发布于 2011-04-28 11:36:19
我不认为InvokeRequired会被绞死。BeginInvoke可能会,但我不认为它会。
没什么主意。
BeginInvoke运行正常,但是UI线程很忙,所以它永远无法运行OnModuleInitializationComplete。这个线程接下来要做什么?它是否作为某个点开始等待(比如调用EndInvoke)?
InvokeRequired返回false,而您的CheckIfAllModulesInitComplete方法挂起。
我会在OnModuleInitializationComplete中添加更多的日志,以显示如果它使用了哪个路径,然后用新信息更新您的问题。
如果您还可以提供有关此方法的代码的更多细节,那么它可能是有用的,特别是在等待此方法完成的任何地方。
发布于 2011-04-28 11:46:18
我将在InvokeRequired之后和BeginInvoke调用之前添加一条日志消息。
我怀疑这是BeginInvoke阻塞,因为UI线程很忙,可能是因为它在等待其他东西。
发布于 2011-04-28 11:17:38
更有可能的是,您有某种竞争条件,这会导致死锁。或者,您的调试信息是混乱的,而这并不是真正阻塞的行。
https://stackoverflow.com/questions/5817716
复制相似问题