我正在创建一个集线器客户端,如下所示:
hub = new HubConnectionBuilder()
.WithUrl(Constants.HubsUrl + "/MainHub", options =>
{
options.Headers.Add(Constants.HeaderToken, token);
options.UseDefaultCredentials = true;
})
.ConfigureLogging(logging =>
{
logging.AddDebug();
logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Warning);
})
.WithAutomaticReconnect(new[] {
TimeSpan.Zero,
TimeSpan.FromSeconds(5),
TimeSpan.FromSeconds(30),
TimeSpan.FromMinutes(1),
TimeSpan.FromMinutes(5)
})
.Build();
hub.Closed += (exception) =>
{
Closed?.Invoke(this, new EventArgs());
if (exception == null)
{
Console.WriteLine("Connection closed without error.");
}
else
{
Console.WriteLine($"Connection closed due to an error: {exception}");
}
return Task.CompletedTask;
};
这一切都很好。
但是我想知道最后一次重新连接尝试是否已完成,以便我可以向用户显示一条消息。
我需要用老式的柜台方式来做,还是有更好的解决方案?