当前位置: 首页>>代码示例>>C#>>正文


C# HubConnection.EnsureReconnecting方法代码示例

本文整理汇总了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();
     }
 }
开发者ID:JonasSyrstad,项目名称:Stardust,代码行数:37,代码来源:Startup.cs

示例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;
     });
 }
开发者ID:CuneytKukrer,项目名称:TestProject,代码行数:41,代码来源:Program.cs


注:本文中的Microsoft.AspNet.SignalR.Client.HubConnection.EnsureReconnecting方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。