2016-03-18 53 views
1

我有一個調用信號R集線器方法的.net控制檯應用程序。 我設法將連接配置爲在發生多次故障後重新啓動,並在超過重試次數後啓動新的集線器實例。信號R集線器啓動掛起

問題是有時候hub.start方法會掛起而沒有任何異常,並且它沒有進入延續。

下面是代碼:

private static void restart() 
    { 
     Logging("Restarting connection", EventLogEntryType.Warning); 

     hubConnection.Start() // it stuck without any error after several retry 
      .ContinueWith((t) => 
     { 

      if (restartCount <= restartRetryCountMax) 
      { 
       if (t.IsFaulted) 
       { 
        restartCount++; 
        restart(); 
       } 
       else 
       { 
        CheckClientStatus(); 
       } 
      } 
      else 
      { 
       restartCount = 0; 
       Logging("Initialize new connection", EventLogEntryType.Information); 
       start();//start a fresh hub instance 
      } 
     }); 
    } 

這是一個錯誤? 我使用signalr版本2.2.0

+0

您在此顯示的代碼沒有任何問題。你需要提供一個[MCVE](http://stackoverflow.com/help/mcve) –

+0

我只是想簡化一下,基本上這個方法在連接斷開時被調用。我不想在每次連接超時時創建新的集線器實例,因此請重新啓動連接而不創建新的集線器實例。如果我放置了一箇中斷點,它將觸發中心啓動方法,然後它將毫無例外地釋放它。這種方法隨機卡住。 –

回答

0

當你調用start方法SignalR嘗試當你的應用程序已經超過了它掛起,並且不能建立一個新的允許的連接的最大數目,以建立新的連接,但 。

有一個默認的併發連接數限制(我認爲在默認情況下是2)

你可以改變它這種方式:

System.Net.ServicePointManager.DefaultConnectionLimit=x 

我會建議關閉退出事件集線器連接:

class Program 
    { 
     static void Main(string[] args) 
     { 
      AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit); 
     } 

     static void CurrentDomain_ProcessExit(object sender, EventArgs e) 
     { 
      /// stop hub connection 
      hubConnection.Stop(); 
     } 
    } 
+2

但爲什麼不進入延續? –