首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >InvokeRequired挂起

InvokeRequired挂起
EN

Stack Overflow用户
提问于 2011-04-28 11:15:35
回答 3查看 1K关注 0票数 2

在下面的方法中,UI线程偶尔挂在语句'if (this.InvokeRequired)'上。

你能帮我找出问题的原因吗?

代码语言:javascript
复制
  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 <<");
  }
EN

回答 3

Stack Overflow用户

发布于 2011-04-28 11:36:19

我不认为InvokeRequired会被绞死。BeginInvoke可能会,但我不认为它会。

没什么主意。

BeginInvoke运行正常,但是UI线程很忙,所以它永远无法运行OnModuleInitializationComplete。这个线程接下来要做什么?它是否作为某个点开始等待(比如调用EndInvoke)?

InvokeRequired返回false,而您的CheckIfAllModulesInitComplete方法挂起。

我会在OnModuleInitializationComplete中添加更多的日志,以显示如果它使用了哪个路径,然后用新信息更新您的问题。

如果您还可以提供有关此方法的代码的更多细节,那么它可能是有用的,特别是在等待此方法完成的任何地方。

票数 1
EN

Stack Overflow用户

发布于 2011-04-28 11:46:18

我将在InvokeRequired之后和BeginInvoke调用之前添加一条日志消息。

我怀疑这是BeginInvoke阻塞,因为UI线程很忙,可能是因为它在等待其他东西。

票数 1
EN

Stack Overflow用户

发布于 2011-04-28 11:17:38

更有可能的是,您有某种竞争条件,这会导致死锁。或者,您的调试信息是混乱的,而这并不是真正阻塞的行。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5817716

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档