最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

when I receive a SignalR core Reconnected (not 'ing) event from my hubconnection, I expect the hub state = Connected, bu

programmeradmin3浏览0评论

when I receive a SignalR core Reconnected event from my hubconnection, I expect the hub state to be Connected, but its often Connecting! This seems somewhat counter intuitive!

I have autoreconnect enabled

I'm probably going to have to wait (in a loop) until state=Connected as I need to kick stuff off!

Or is there a better approach?

when I receive a SignalR core Reconnected event from my hubconnection, I expect the hub state to be Connected, but its often Connecting! This seems somewhat counter intuitive!

I have autoreconnect enabled

I'm probably going to have to wait (in a loop) until state=Connected as I need to kick stuff off!

Or is there a better approach?

Share Improve this question edited Feb 8 at 19:40 fpdave100 asked Feb 7 at 12:40 fpdave100fpdave100 616 bronze badges 2
  • Use the Reconnected event to kick stuff off? – Brennan Commented Feb 7 at 17:01
  • Sorry, important typo - it is the Reconnected event I'm handling, and finding that state=connecting! Very sorry – fpdave100 Commented Feb 8 at 19:41
Add a comment  | 

1 Answer 1

Reset to default 0

You are right, since the event only trigger once, you have to loop until state really changed.

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.");
};

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论