1

在我们的应用程序中,客户端软件使用 SignalR 的 .NET 客户端库。进行了两个几乎相同的调用,但只执行了第一个。

对象进行以下调用:

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

AddSubscription() 在其父级上实现:

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

在这种情况下,客户端调用是 SignalR 客户端的 IHubProxy 包装器,它返回与 IHubProxy.Invoke() 相同的任务。_realtimeClient 本身最终是一个在整个应用程序中共享的静态客户端实例。在此之前,我们在调用或订阅服务器发送的事件方面没有问题。

无论出于何种原因,只有第一个 AddSubscription 通过。如果我交换它们,那么无论哪个现在先通过。如果我单步执行,它们都会执行。

什么可能阻止它们立即连续执行?

编辑:我应该补充一点,虽然客户端实例是静态的,但它的方法或属性都不是。

4

1 回答 1

2

等待异步方法 Invoke 完成,看看是否有异常:_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);
于 2013-04-10T01:28:53.120 回答