private void DoWork_Handler(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; ControllerReply rpl; RemoteControllerLink _ctrl = (RemoteControllerLink)e.Argument; while (true) { lock (_ctrl) { rpl = _ctrl.HeartbeatPoll(); if (rpl.status == ControllerReply.Status.SUCCESS) { byte id = _ctrl.Ssr.signStatusEntry[0].frameId; if (id != 0 && _ctrl.Frames[id] == null) { rpl = _ctrl.SignRequestStoredFrm(id); } if (rpl.status == ControllerReply.Status.SUCCESS) { worker.ReportProgress(id); } } } for (int i = 0; i < 10; i++) { if (worker.CancellationPending) { return; } Thread.Sleep(100); } } }
private void btnFrmGetFromCtrller_Click(object sender, RoutedEventArgs e) { try { byte frmId = 1; if (!byte.TryParse(tbFrmFrameId.Text, out frmId) || frmId == 0) { throw new Exception("Illegal Frame ID"); } RemoteControllerLink ctrl = remoteConctrollerLinks[parameters.ControllerID]; ControllerReply rpl; rpl = ctrl.SignRequestStoredFrm(frmId); if (rpl.status != ControllerReply.Status.SUCCESS) { throw new Exception(rpl.status.ToString()); } if ((ctrl.Frames[frmId] is SignSetTextFrame)) { LoadFrame((ctrl.Frames[frmId] as SignSetTextFrame)); return; } else if ((ctrl.Frames[frmId] is SignSetGraphicsFrame)) { LoadFrame((ctrl.Frames[frmId] as SignSetGraphicsFrame)); } else if ((ctrl.Frames[frmId] is SignSetHighResolutionGraphicsFrame)) { LoadFrame((ctrl.Frames[frmId] as SignSetHighResolutionGraphicsFrame)); return; } else { throw new Exception("Illegal frame type from controller"); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }