コード例 #1
0
        private static void InvokeMethod(string type, string type1)
        {
            Debug.WriteLine(String.Format("Recieved Message From Server On :{0}", System.DateTime.Now.ToString()));
            Debug.WriteLine("Message Received");
            ServiceMonitoring serviceMonitoring = new ServiceMonitoring();

            serviceMonitoring.UpdatedOn = DateTime.Now;

            var vvv = ApplicationGlobalVariables.ServiceScheduled.Where(p => p.Key == "Test").Select(s => s.Value).FirstOrDefault();

            ApplicationGlobalVariables.ServiceScheduled.TryUpdate("Test", serviceMonitoring, vvv);
        }
コード例 #2
0
        public static async Task <bool> SignalrHandler()
        {
            bool connected = false;

            try
            {
                ServiceMonitoring s = new ServiceMonitoring();
                s.UpdatedOn = DateTime.Now;
                ApplicationGlobalVariables.ServiceScheduled.TryAdd("Test", s);

                var url = "http://localhost:8089";

                var _hubConnection    = new HubConnection(url);
                var MarcolinMainProxy = _hubConnection.CreateHubProxy("MyHub");
                MarcolinMainProxy.On <string, string>("addMessage", InvokeMethod);

                await _hubConnection.Start();

                if (_hubConnection.State == ConnectionState.Connected)
                {
                    Debug.WriteLine("Hub Connected");
                    connected              = true;
                    _hubConnection.Closed += Connection_Closed;
                    ApplicationGlobalVariables.aTimer.Enabled = false;
                    return(connected);
                }
                else
                {
                    return(connected);
                }

                //if (_hubConnection.State == ConnectionState.Disconnected)
                //{
                //    Connection_Closed();
                //}
            }
            catch (Exception)
            {
                return(connected);
            }
        }