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


C# HubConnection.Stop方法代码示例

本文整理汇总了C#中Microsoft.AspNet.SignalR.Client.HubConnection.Stop方法的典型用法代码示例。如果您正苦于以下问题:C# HubConnection.Stop方法的具体用法?C# HubConnection.Stop怎么用?C# HubConnection.Stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.AspNet.SignalR.Client.HubConnection的用法示例。


在下文中一共展示了HubConnection.Stop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: StartRealtimeConnection

        private async Task<ApiResultBase> StartRealtimeConnection(ConnectExtruderModel connectExtruderModel)
        {
            try
            {
                _connection = new HubConnection(SOS_URL);
                _proxy = _connection.CreateHubProxy("SosHub");

                _proxy.On<int?, TimeSpan?>("setLights", OnSetLightsEventReceived);
                _proxy.On<int?, TimeSpan?>("setAudio", OnSetAudioEventReceived);
                _proxy.On<ModalDialogEventArgs>("modalDialog", OnModalDialogEventReceived);
                _proxy.On("forceDisconnect", OnForceDisconnect);
                _proxy.On<TrayIcon>("setTrayIcon", OnSetTrayIcon);
                _proxy.On<TrayNotifyEventArgs>("trayNotify", OnTrayNotify);
                _connection.Error += ConnectionOnError;
                _connection.StateChanged += ConnectionOnStateChanged;
                _connection.Closed += ConnectionOnClosed;
                await _connection.Start();
                var result = await _proxy.Invoke<ApiResultBase>("connectExtruder", connectExtruderModel);
                if (!result.Success)
                {
                    _connection.Stop();
                }
                return result;
            }
            catch (Exception ex)
            {
                _log.Error("Unable to start realtime connection to SoS Online", ex);
                return new ApiResultBase {Success = false, ErrorMessage = ex.Message};
            }
        }
开发者ID:AutomatedArchitecture,项目名称:SirenOfShame,代码行数:30,代码来源:SosOnlineService.cs

示例2: CallToServer

        void CallToServer()
        {
            Console.WriteLine("Input your name ==>");
            string inputName = Console.ReadLine();

            var hubConnection = new HubConnection("http://localhost:50515/");
            hubConnection.Error += hubConnection_Error;
            IHubProxy consoleHubProxy = hubConnection.CreateHubProxy("HubCenter");
            consoleHubProxy.On("broadcastMessage", (string name, string message) =>
            {
                Console.WriteLine("{0} say: {1}", name, message);
            });

            hubConnection.Start().Wait();

            string sayWhat;
            Console.WriteLine("Say something.");
            while ((sayWhat = Console.ReadLine()) != "")
            {
                try
                {
                    consoleHubProxy.Invoke("CallFromConsole", new ClientModel { Name = inputName, Message = sayWhat }).Wait();
                }
                catch(Exception ex)
                {

                }
            }

            hubConnection.Stop();
        }
开发者ID:wangchez,项目名称:Learn-SignalR-Demo-ClientSide,代码行数:31,代码来源:Program.cs

示例3: SendCompleteNotification

        private static async Task SendCompleteNotification(Message message, string uri)
        {
            var hubConnection = new HubConnection(url);
            hub = hubConnection.CreateHubProxy("GifServerHub");
            await hubConnection.Start();

            Console.WriteLine("Invoked  GifGenerationCompleted with URL: {0}", uri);
            await hub.Invoke("GifGenerationCompleted", message.HubId, uri);

            hubConnection.Stop();
        }
开发者ID:kirpasingh,项目名称:MicrosoftAzureTrainingKit,代码行数:11,代码来源:Program.cs

示例4: MainAsync

        private async Task MainAsync()
        {
            _hubConnection = CreateConnection();
            Console.WriteLine("Created connection, waiting 1 minute to start it.");
            Thread.Sleep(TimeSpan.FromMinutes(1));
            await _hubConnection.Start();

            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
            _hubConnection.Stop();
        }
开发者ID:jbmercha,项目名称:SignalRIssue2956Repro,代码行数:11,代码来源:Program.cs

示例5: Main

        static void Main(string[] args)
        {
            var con = new HubConnection("http://localhost/SignalRDemo");

            var adminHub = con.CreateHubProxy("admin");

            con.Start().ContinueWith(t => Console.WriteLine("Connected")).Wait();

            adminHub.On<dynamic>("orderReceived", order => Console.WriteLine(order));

            Console.Read();
            con.Stop();
        }
开发者ID:pellec,项目名称:SignalRCartDemo,代码行数:13,代码来源:Program.cs

示例6: Main

        static void Main(string[] args)
        {
            var url = "http://localhost:8080/";
            var connection = new HubConnection(url);

            //必须在Connection连接之前创建Hub
            var serviceHub = connection.CreateHubProxy("MyServiceHub");

            //注册该Hub的Hit方法对应的客户端处理程序
            serviceHub.On<string,string>("pushMessage", (p,q) =>
            {
                Console.WriteLine(p+":"+q);
            });

            Console.WriteLine("正在连接服务器...");
            connection.Start().Wait();

            if (connection.State == ConnectionState.Disconnected)
            {
                Console.WriteLine("连接服务器失败");
            }
            else
            {
                Console.WriteLine("连接服务器成功");
                serviceHub.Invoke("HelloWorld").Wait();
                while (true)
                {
                    Console.WriteLine("请选择:\n1.发送消息\n2.发送测试对象\n3.获取SessionID\n0.退出");
                    string key = Console.ReadLine();
                    if (key == "1")
                    {
                        Console.WriteLine("请输入消息内容:");
                        serviceHub.Invoke("SendMessage", Console.ReadLine()).Wait();
                    }
                    else if (key == "2")
                    {
                        var obj = new { Name = "小明", Age = 18 };
                        serviceHub.Invoke("SendObject",obj).Wait();
                    }
                    else if (key == "3")
                    {
                        Console.WriteLine("SessionID:" + serviceHub.Invoke<string>("GetSessionId").Result);
                    }
                    else if (key == "0")
                    {
                        connection.Stop();
                        return;
                    }
                }
            }
        }
开发者ID:RenYueHD,项目名称:SignalRExtendLib,代码行数:51,代码来源:Program.cs

示例7: Signal_Excute

        /// <summary>
        /// 互动发送消息
        /// </summary>
        /// <param name="HubName"></param>
        /// <param name="HubAction"></param>
        public void Signal_Excute(String HubName, Action<IHubProxy> HubAction)
        {
            var HubUrl = ConfigurationManager.AppSettings["AdminSiteUrl"] + "/signalr";

            var Connection = new HubConnection(HubUrl);

            var HubItem = Connection.CreateHubProxy(HubName);

            Connection.Start().ContinueWith(task =>
            {
                if (!task.IsFaulted)
                {
                    HubAction(HubItem);
                }
            }).Wait();

            Connection.Stop();
        }
开发者ID:seven1276,项目名称:yycms,代码行数:23,代码来源:CodeCompile.cs

示例8: Main

        static void Main(string[] args)
        {
            String hub = ConfigurationManager.AppSettings["hub"];

            HubConnection myHubConn;
            IHubProxy myHub;

            myHubConn = new HubConnection(hub);
            myHub = myHubConn.CreateHubProxy("resultatServiceHub");

            myHubConn.Error += ex => Console.WriteLine("SignalR error: {0}", ex.Message, ex.InnerException);

            myHubConn.TraceLevel = TraceLevels.None;
            myHubConn.TraceWriter = Console.Out;

            myHubConn.Start()
                .ContinueWith((prevTask) =>
                {
                    myHub.Invoke("Join", "ResultService");
                    myHub.Invoke("AddtoGroup", "");
                }).Wait();

            myHub.On<Participant>("newPass", (data) =>
                {
                    foreach (ParticipantClass c in data.Classes)
                    {
                        myHub.Invoke<ICollection<Participant>>("GetCurrentResults", c.Id)
                            .ContinueWith((result) =>
                            {
                                var d = result.Result;
                                var json = JsonConvert.SerializeObject(d, Formatting.Indented);
                                System.IO.File.WriteAllText(@"c:\temp\" + c.Name + ".json", json);
                            });
                    }
                }
            );
            Console.ReadLine();

            myHubConn.Stop();
            Console.WriteLine("Stopped");
        }
开发者ID:kjorlaug,项目名称:KjeringiOpen,代码行数:41,代码来源:Program.cs

示例9: Upload

		public async Task<ActionResult> Upload(string site)
		{
			for (int i = 0; i < Request.Files.Count; i++)
			{
				var file = Request.Files[i];
				Guid id = Guid.NewGuid();


				byte[] logo = new byte[file.ContentLength];
				file.InputStream.Read(logo, 0, file.ContentLength);


				_dataPersistor.SaveImage(logo, site, id);
				var hubConnection = new HubConnection("http://localhost:4785/");
				IHubProxy stockTickerHubProxy = hubConnection.CreateHubProxy("NotificationHub");
				await hubConnection.Start();
				await stockTickerHubProxy.Invoke("NotifyPostedImage", new NotifyPostedImageCommand { Id = id, Secret = _secret, Image = logo, Timestamp = DateTime.Now, SiteName = (string)RouteData.Values["site"] });
				hubConnection.Stop();
			}
			return Json(new { success = true }, JsonRequestBehavior.AllowGet);
		}
开发者ID:pirovorster,项目名称:ServiceHub,代码行数:21,代码来源:ImagePostsController.cs

示例10: Main

        static void Main(string[] args)
        {
            Console.Title = "Drawing Board Virtual";
            Console.SetWindowSize(80, 60);
            Console.BackgroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Black;
            Console.Clear();
            var server = "http://localhost:52234/";
            var hubConn = new HubConnection(server);
            var hubProxy = hubConn.CreateHubProxy("board");
            hubProxy.On("clear", () =>
            {
                Console.BackgroundColor = ConsoleColor.White;
                Console.Clear();
            });
            hubProxy.On("drawPoint", (int x, int y, int color) => DrawPoint(x, y, color));
            hubProxy.On("update", (int[,] buffer) =>
            {
                for (int x = 0; x < buffer.GetLength(0); x++)
                {
                    for (int y = 0; y < buffer.GetLength(1); y++)
                    {
                        if (buffer[x, y] != 0)
                        {
                            DrawPoint(x, y, buffer[x, y]);
                        }
                    }
                }
            });
            hubConn.Start().ContinueWith(c =>
            {
                if (c.IsFaulted)
                {
                    Console.WriteLine("Error to conect");
                }
            });

            Console.ReadLine();
            hubConn.Stop();
        }
开发者ID:mikemajesty,项目名称:Curso_SignalR_DeMedia,代码行数:40,代码来源:Program.cs

示例11: Main

        private static void Main(string[] args) {
            Console.Title = "Console drawing board viewer";
            Console.SetWindowSize(80, 50);
            Console.BackgroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Black;
            Console.Clear();

            var server = "http://localhost:52682/signalr";
            var hubConn = new HubConnection(server, false);
            var hubProxy = hubConn.CreateHubProxy("drawingBoard");


            hubProxy.On("clear", () => {
                        Console.BackgroundColor = ConsoleColor.White;
                        Console.Clear();
                    });

            hubProxy.On("drawPoint", (int x, int y, int color) => {
                        DrawPoint(x, y, color);
                    });

            hubProxy.On("update", (int[,] buffer) => {
                    for (int x = 0; x < buffer.GetLength(0); x++) {
                        for (int y = 0; y < buffer.GetLength(1); y++) {
                            if (buffer[x, y] != 0)
                                DrawPoint(x, y, buffer[x, y]);
                        }
                    }
                });

            hubConn.Start().ContinueWith(t => {
                    if (t.IsFaulted) {
                        Console.WriteLine("Error connecting to "
                            + server + ". Are you using the right URL?");
                    }
                });
            Console.ReadLine();
            hubConn.Stop();
        }
开发者ID:Geronimobile,项目名称:DotNetExamIntro,代码行数:39,代码来源:Program.cs

示例12: Main

        private static void Main(string[] args) {
            Console.Clear();
            Console.WriteLine("(Enter port number");
            var port = Console.ReadLine();
            string host = "http://localhost:" + port;
            while (true) {
                var connection = new HubConnection(host);
                Console.Clear();
                Console.WriteLine("(Enter 'adam' or 'admin' as username to access private methods)");
                Console.Write("Enter your username: ");
                var username = Console.ReadLine();
                Console.Write("Enter your password: ");
                var password = Console.ReadLine();

                var authCookie = GetAuthCookie(host + "/account/login", username, password).Result;

                if (authCookie == null) {
                    Console.WriteLine("Impossible to get the token. Press a key to try again.");
                    Console.ReadKey();
                    continue;
                }

                Console.WriteLine("Token obtained");
                connection.CookieContainer = new CookieContainer();
                connection.CookieContainer.Add(authCookie);
                var proxy = connection.CreateHubProxy("EchoHub");
                proxy.On<string>("Message", msg => Console.WriteLine("    Received: " + msg));
                connection.Start().Wait();

                Invoke(proxy, "PublicMessage", username);
                Invoke(proxy, "MembersMessage", username);
                Invoke(proxy, "AdminsMessage", username);
                Invoke(proxy, "PrivateMessage", username);
                Console.WriteLine("\n\nPress any key to try again, Ctrl-C to exit");
                Console.ReadKey();
                connection.Stop();

            }
        }
开发者ID:Geronimobile,项目名称:DotNetExamIntro,代码行数:39,代码来源:Program.cs

示例13: Main

        public static void Main(string[] args)
        {
            var connection = new HubConnection("http://127.0.0.1:8088/");
            var myHub = connection.CreateHubProxy("ChatHub");

            connection.Start().ContinueWith(task =>
            {
                if (task.IsFaulted)
                {
                    Console.WriteLine("There was an error opening the connection:{0}",
                                      task.Exception.GetBaseException());
                }
                else
                {
                    Console.WriteLine("Connected");
                }

            }).Wait();

            myHub.On<string>("addMessage", param =>
            {
                Console.WriteLine(param);
            });

            Console.Write("Your name: ");
            string name = Console.ReadLine();

            myHub.Invoke<string>("Chat", "Online: " + name).Wait();

            while (true)
            {
                string message = Console.ReadLine();
                myHub.Invoke<string>("Chat", name + ":" + message).Wait();
                if (message == "quit")
                    break;
            }
            connection.Stop();
        }
开发者ID:JingqingZ,项目名称:SignalRConsoleChat,代码行数:38,代码来源:Program.cs

示例14: Main

        static void Main(string[] args)
        {
            var connection = new HubConnection("http://localhost:57459/");
            connection.TraceLevel = TraceLevels.All;
            connection.TraceWriter = System.Console.Out;
            var proxy = connection.CreateHubProxy("ChatHub");
            connection.Start()
                .ContinueWith(t =>
                    {
                        throw t.Exception.GetBaseException();
                    },TaskContinuationOptions.OnlyOnFaulted)
                .ContinueWith(_ =>
                {
                    for (int i = 0; i < 1000; i++)
                    {
                        Thread.Sleep(TimeSpan.FromMilliseconds(new Random().Next(1, 15)));
                        var message = string.Format("Message number {0}", i);

                        System.Console.WriteLine(message);
                        proxy.Invoke("MessageGroup", "SignalR", message).Wait();
                    }
                }).ContinueWith(_ => connection.Stop());
            System.Console.ReadLine();
        }
开发者ID:Teleopti,项目名称:signalr-signalr-messagebus,代码行数:24,代码来源:Program.cs

示例15: RunConnectDisconnect

        public static IDisposable RunConnectDisconnect(bool scaleout, int nodes = 1, int connections = 1000)
        {
            IHttpClient client;
            IDisposable disposable = TryGetClient(scaleout, nodes, out client);

            for (int i = 0; i < connections; i++)
            {
                var connection = new HubConnection("http://foo");
                var proxy = connection.CreateHubProxy("SimpleEchoHub");
                var wh = new ManualResetEventSlim(false);

                proxy.On("echo", _ => wh.Set());

                try
                {
                    connection.Start(client).Wait();

                    proxy.Invoke("Echo", "foo").Wait();

                    if (!wh.Wait(TimeSpan.FromSeconds(10)))
                    {
                        Debugger.Break();
                    }
                }
                finally
                {
                    connection.Stop();
                }
            }

            return disposable;
        }
开发者ID:Choulla-Naresh8264,项目名称:SignalR,代码行数:32,代码来源:StressRuns.cs


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