本文整理汇总了C#中Microsoft.AspNet.SignalR.Client.HubConnection.EnsureReconnecting方法的典型用法代码示例。如果您正苦于以下问题:C# HubConnection.EnsureReconnecting方法的具体用法?C# HubConnection.EnsureReconnecting怎么用?C# HubConnection.EnsureReconnecting使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.AspNet.SignalR.Client.HubConnection
的用法示例。
在下文中一共展示了HubConnection.EnsureReconnecting方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RegisterForNotifications
private static void RegisterForNotifications()
{
try
{
var userName = GetConfigServiceUser();
var password = GetConfigServicePassword();
GlobalHost.HubPipeline.RequireAuthentication();
hubConnection = new HubConnection(GetConfigLocation());
if (hubConnection.CookieContainer == null) hubConnection.CookieContainer = new CookieContainer();
//hubConnection.Credentials = new NetworkCredential(userName, password, GetConfigServiceDomain());
ConfigCacheHelper.SetCredentials(hubConnection);
hub = hubConnection.CreateHubProxy("configSetHub");
hub.On("changed",
(string id, string name) =>
{
if (string.Equals(id, "user", StringComparison.OrdinalIgnoreCase))
{
UpdateUser(name);
}
else
{
UpdateEnvironmet(id, name);
}
});
hubConnection.EnsureReconnecting();
hubConnection.Reconnecting += hubConnection_Reconnecting;
hubConnection.Closed += hubConnection_Closed;
hubConnection.Error += hubConnection_Error;
hubConnection.StateChanged += hubConnection_StateChanged;
hubConnection.Start();
CreatePingService();
}
catch (Exception ex)
{
ex.Log();
}
}
示例2: Do
private static Task Do()
{
string url = "http://192.168.70.118:1980";
var connection = new HubConnection(url);
IHubProxy hub = connection.CreateHubProxy("echo");
var httpClient = new DefaultHttpClient();
var transport = new AutoTransport(
httpClient,
new IClientTransport[]
{
//new ServerSentEventsTransport(httpClient),
new LongPollingTransport(httpClient)
}
);
//connection.Error +=
// error => ConsoleColor.Red.AsColorFor(() => Console.WriteLine("Error from connection: {0}", error));
connection.Closed += () =>
{
Console.WriteLine("Closed");
//if (!connection.EnsureReconnecting())
//{
// Task.Delay(TimeSpan.FromSeconds(30)).ContinueWith(t => connection.Start().Wait());
//}
if (!connection.EnsureReconnecting())
{
Task.Factory.StartNew(() => Thread.Sleep(TimeSpan.FromSeconds(30)))
.ContinueWith(t => connection.Start().Wait());
}
};
connection.ConnectionSlow += () => Console.WriteLine("ConnectionSolw!");
connection.Received += data => Console.WriteLine(string.Format("Received:{0}", data));
connection.Reconnected += () => Console.WriteLine("Reconnected!");
connection.StateChanged +=
state =>
Console.WriteLine("StateChanged:From {0} to {1}", state.OldState, state.NewState);
return connection.Start(transport).ContinueWith(_ =>
{
Console.WriteLine("Connected, transport is :{0}", connection.Transport.Name);
return hub;
});
}