Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 调用所需的挂起_C#_.net_Multithreading_Invokerequired - Fatal编程技术网

C# 调用所需的挂起

C# 调用所需的挂起,c#,.net,multithreading,invokerequired,C#,.net,Multithreading,Invokerequired,在以下方法中,UI线程偶尔挂起在语句'if(this.invokererequired)处 你能帮我找出问题的原因吗 public void OnModuleInitializationCompleted(object sender, EventArgs e) { ModuleStatusWindow.Logger.LogMessage("OnModuleInitializationCompleted", LogMessageType.Information, "Received

在以下方法中,UI线程偶尔挂起在语句'if(this.invokererequired)

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

  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 <<");
  }
模块初始化完成时的公共无效(对象发送方,事件参数e) { ModuleStatusWindow.Logger.LogMessage(“OnModuleInitializationCompleted”,LogMessageType.Information,“Received{0}”,发送方为IModule.Name); if(this.invokererequired) { this.BeginInvoke(新的ECEventsHandler(OnModuleInitializationCompleted)),发送方,e; } 其他的 { 选中AllModulesInitComplete(); } } 私有无效检查AllModulesInitComplete() { ModuleStatusWindow.Logger.LogMessage(“CheckIfAllModulesInitComplete”,LogMessageType.Information,“输入>>”; this.\u moduleStatusGrid.DataSource=this.\u moduleDataList.ToArray(); 这是._moduleStatusGrid.Invalidate(); ModuleStatusWindow.Logger.LogMessage(“CheckIfAllModulesInitComplete”,LogMessageType.Information,“更新的网格控制…”); if(this.\u moduleDataList.Count(moduleData=>!moduleData.IsInitOver)==0) { 此._footprint.DeActivate(); ModuleStatusWindow.Logger.LogMessage(“CheckIfAllModulesInitComplete”,LogMessageType.Information,“正在停止消息列表…”); ClientMessageListner.Stop(); ModuleStatusWindow.Logger.LogMessage(“CheckIfAllModulesInitComplete”,LogMessageType.Information,“关闭窗口…”); 这个。关闭(); }
ModuleStatusWindow.Logger.LogMessage(“CheckIfAllModulesInitComplete”,LogMessageType.Information,“离开更有可能的是,您遇到了某种导致死锁的竞争条件。或者,您的调试信息被弄乱了,这并不是真正阻塞的线路。

我认为InvokeRequired不太可能挂起。BeginInvoke可能挂起,但我认为不会

没什么主意

BeginInvoke正在正确运行,但UI线程很忙,因此它无法在ModuleInitializationComplete上运行。该线程接下来做什么?它是否会在某个时间点开始等待(如调用EndInvoke)

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

我会在OnModuleInitializationComplete中添加更多日志记录,以显示它所采用的路径,然后用新信息更新您的问题。

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

我会在调用所需的调用之后和BeginInvoke调用之前添加日志消息


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

您具体是如何确定它挂起的?从日志文件中,我可以看到此InvokeRequest语句之前的日志项。但是CheckIfAllModulesInitComplete中的日志项不存在日志文件中没有任何可能是对记录器的调用导致了挂起?@BugFinder:记录器模块非常稳定。我不认为挂起在记录器中。我不是说它不稳定,但可能是它导致了锁,因此不会返回。只是想一想。特别是如果不总是很容易跟踪,我添加了源代码在我的第一篇文章中,CheckIfAllModulesInitComplete的。该方法中的第一个日志条目在日志文件Notice中不可用!InvokeRequired可能会挂起,因为它锁定了当前控件。请参阅下面URL[链接]中的
lock(this)
,例如,如果有另一个线程A,请先保留资源B,然后调用InvokeRequired同时,你的主线程(UI线程可能持有锁)需要资源B。它是一个死锁。。。