xkcd
xkcd

Reputation: 2590

Keeping connection alive in the right way from c# client

I have a self hosted signalr hub and two types of clients those connect to it.

In windows services, how can I handle the disconnected event (Restarting connection after 2 seconds behaviour) as I used in web apps?

Thanks in advance,

Upvotes: 0

Views: 5209

Answers (2)

xkcd
xkcd

Reputation: 2590

This is what I need:

http://www.asp.net/signalr/overview/guide-to-the-api/hubs-api-guide-net-client#connectionlifetime

        hubConnection.Closed += () => {
            connected = false;
            while (!connected)
            {
                System.Threading.Thread.Sleep(2000);
                hubConnection = new HubConnection("http://localhost:8080/signalr", "source=" + feed, useDefaultUrl: false);
                priceProxy = hubConnection.CreateHubProxy("UTHub");
                hubConnection.Start().Wait();
                connected = true;
            }
        };

Upvotes: 4

SHM
SHM

Reputation: 1952

to perform custom logic when disc a client gets disconnected is to override ondisconnected method on hub class, like this:

public override Task OnDisconnected(bool stopCalled)
    {
        // your custom code here...
        return base.OnDisconnected(stopCalled);
    }

Upvotes: 0

Related Questions