AUSteve
AUSteve

Reputation: 3248

Signalr hub connection management in client winforms app

I'm looking for advice on how best to handle Signalr hub connections in a winforms app acting as the client.

I have a web app as the Signalr (v0.5.1) server and a client winforms app using hubs. Everything works as desired, I just feel I have too many Signalr connections to the server. For each form I am creating a new HubConnection instance because the hub needs to subscribe to events before the connection is started. One or two hubs are used on each form and not all forms subscribe to server events, some just invoke server-side methods.

Can I have one (static) HubConnection (eg a property of the Program) and use it for all forms? This strategy implies start/stop/state management hassles as each form may subscribe to different events.

What's the best strategy for managing Signalr connections (and hubs) in a .Net client?

Upvotes: 1

Views: 2426

Answers (1)

davidfowl
davidfowl

Reputation: 38784

Yes, you only need one connection for your entire application. How you choose to store that is up to you (static vs DI etc).

Upvotes: 2

Related Questions