2013-04-09 89 views
1

在我們的應用程序中,客戶端軟件正在使用SignalR的.NET客戶端庫。兩個幾乎完全相同的調用被創建,但只有第一個執行。某些順序SignalR調用丟失

一個目的提出下列調用:

AddSubscription(typeof(ObjA).Name); 
AddSubscription(typeof(ObjB).Name); 

AddSubscription()被其父實施:

_subscribedTypes.Add(type); 
_realtimeClient.Invoke("Subscribe", type); 

客戶端在這種情況下調用是IHubProxy爲SignalR客戶一個封裝器,返回與IHubProxy.Invoke()相同的任務。 _realtimeClient本身最終是一個在應用程序中共享的靜態客戶端實例。我們在調用或訂閱服務器發送的事件之前沒有問題。

無論出於何種原因,只有第一個AddSubscription會通過。如果我交換它們,那麼現在先通過的任何一個都會通過。如果我通過,他們都執行。

什麼可能會阻止這兩者立即連續執行?

編輯:我應該補充一點,雖然客戶端實例是靜態的,但它的方法或屬性都不是。

回答

2

等待異步方法調用以完成以查看是否收到異常: _realtimeClient.Invoke(「Subscribe」,type).Wait();

確保您訂閱的所有事件,你可能有一個錯誤事件

 var hubConnection = new HubConnection("http://url/"); 
     hubConnection.TraceWriter = Console.Out; 
     hubConnection.Closed +=() => Console.WriteLine("hubConnection.Closed"); 
     hubConnection.ConnectionSlow +=() => Console.WriteLine("hubConnection.ConnectionSlow"); 
     hubConnection.Error += (error) => Console.WriteLine("hubConnection.Error {0}: {1}", error.GetType(), error.Message); 
     hubConnection.Reconnected +=() => Console.WriteLine("hubConnection.Reconnected"); 
     hubConnection.Reconnecting +=() => Console.WriteLine("hubConnection.Reconnecting"); 
     hubConnection.StateChanged += (change) => Console.WriteLine("hubConnection.StateChanged {0} => {1}", change.OldState, change.NewState);