当我从我的HubConnection中重新连接(不是')事件时,我期望连接到Hub状态=连接,但它经常连接

问题描述 投票:0回答:1

当我收到一个信号核心reconnected从我的HubConnection中获得的事件时,我希望将连接到轮毂状态,但通常会连接连接! 这似乎有些反直观!

我已启用了autoReconnect

我可能必须等待(循环),直到状态=连接,因为我需要启动东西!

或有更好的方法?
asp.net-core signalr .net-8.0
1个回答
0
投票

您是正确的,因为事件仅触发一次,所以您必须循环直到状态真正改变。

HubConnection.Reconnected += async (connectionId) => { Console.WriteLine($"Reconnected with ConnectionId: {connectionId}"); // Loop until the state changes to Connected while (HubConnection.State != HubConnectionState.Connected) { Console.WriteLine($"Waiting for connection to stabilize... Current state: {HubConnection.State}"); await Task.Delay(500); // Wait for 500ms before checking again } Console.WriteLine("Connection is fully established."); };
    
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.