public void Start() { SendStationClientStateMessage( new StationClientState { State = StationClientStateEnum.INFO, Message = "单元站点客户端开启!", CreateDateTime = DateTime.Now }); Task.Factory.StartNew(async() => { await signalrService.Start(); while (!token.IsCancellationRequested) { var ret = StationClientFlow(); if (ret == false) { while (ret == false) { ret = StationDevice.SetAlarm(true); SendStationClientStateMessage( new StationClientState { State = StationClientStateEnum.ERROR, Message = "物料调用失败,发送错误信息至设备!", CreateDateTime = DateTime.Now }); Thread.Sleep(1000); } bool dev_reset = false; while (dev_reset == false) { StationDevice.GetReset(ref dev_reset); SendStationClientStateMessage( new StationClientState { State = StationClientStateEnum.INFO, Message = "物料调用失败,等待设备的复位信号", CreateDateTime = DateTime.Now }); Thread.Sleep(1000); } } Thread.Sleep(1000); } }, token.Token); Task.Factory.StartNew(async() => { await signalrService.Start(); while (!token.IsCancellationRequested) { SendFeedingSignal(); Thread.Sleep(1000); } }, token.Token); }
public async static void MainTest() { signalrService = new SignalrService("http://localhost/Agv", "AgvMissonHub"); signalrService.OnMessage <AgvOutMisson>(AgvReceiveActionEnum.receiveOutMissionMessage.EnumToString() , (s) => { Console.WriteLine("[receive]:" + s.Id); }); await signalrService.Start(); while (true) { string data = Console.ReadLine(); Console.WriteLine("[send]:" + data); await signalrService.Send <AgvOutMisson>(AgvSendActionEnum.SendOutMission.EnumToString(), new AgvOutMisson() { Id = data }); } }