2
SignalR 클라이언트 연결이 끊어지면 클라이언트가 다시 연결하려고합니다. 이것을 구현하기위한 좋은 패턴입니까? 나는 연결을 다시 시작하여 SignalR 연결에서 Closed 이벤트를 처리하는 것에 대해 언급하고 있습니다.SignalR 클라이언트 연결 유지
public class OnPremiseWebHubClient
{
private HubConnection _hubConnection;
private IHubProxy _hubProxy;
private OnPremiseWebHubClient() { }
static OnPremiseWebHubClient() { }
private static readonly OnPremiseWebHubClient _instance = new OnPremiseWebHubClient();
public static OnPremiseWebHubClient Instance { get { return _instance; } }
public async Task Start()
{
_hubConnection = new HubConnection("http://OnPremiseWeb/");
_hubProxy = _hubConnection.CreateHubProxy("OnPremiseHub");
// IS THIS A GOOD PATTERN FOR KEEPING THE CONNECTION ALIVE?
_hubConnection.Closed += async() =>
{
// reconnect if we close
await _hubConnection.Start();
};
await _hubConnection.Start();
}
}