예제 #1
0
        public Form1()
        {
            InitializeComponent();

            string url        = @"http://localhost:8080/";
            var    connection = new HubConnection(url);

            _hub = connection.CreateHubProxy("TestHub");
            connection.Start().Wait();

            _hub.On("SendInfo", x => {
                DtoContacto contacto = JsonConvert.DeserializeObject <DtoContacto>(x);

                TxtName.Invoke((MethodInvoker) delegate {
                    // Running on the UI thread
                    TxtName.Text = contacto.Nombre;
                });

                TxtLastName.Invoke((MethodInvoker) delegate {
                    // Running on the UI thread
                    TxtLastName.Text = contacto.Apellido;
                });

                TxtPhone.Invoke((MethodInvoker) delegate {
                    // Running on the UI thread
                    TxtPhone.Text = contacto.Telefono;
                });
            });

            _hub.On("SendNotify", x => {
                MessageBox.Show("Nueva orden");
            });
        }