private void btnClose_Click(object sender, EventArgs e) { if (ProcessingThread.IsBusy) { ProcessingThread.CancelAsync(); } Close(); }
private void KinectViewer_Loaded(object sender, RoutedEventArgs e) { this.ShutdownProcessingThread(); var sensor = this.KinectSensorManager == null ? null : this.KinectSensorManager.KinectSensor; this.processingThread = new ProcessingThread(sensor, this.DepthImageReady, this.ResetOutput); // We need to shut down the processing thread when this main thread is shut down. this.Dispatcher.ShutdownStarted += this.Dispatcher_ShutdownStarted; }
public PluginClient(int sendPort, int receivePort) { _sendSocket = new SendSocket(HostName, sendPort); _receiveSocket = new ReceiveSocket(HostName, receivePort); _sendSocket.Connection += connected => SocketConnectionHandler(_sendSocket, connected); _receiveSocket.Connection += connected => SocketConnectionHandler(_receiveSocket, connected); _receiveSocket.MessageReceived += ReceiveSocketOnMessageReceived; _eventProcessingThread = new ProcessingThread("PluginClient Event Processing thread", EventProcessingIteration); }
public void Stop() { if (!IsRunning) { throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "{0} is already stopped.", GetType().Name)); } StopRequested = true; ProcessingThread.Join(); StopRequested = false; }
public PageLoader( string filename, PageIndexer indexer, VirtualTextureInfo info ) { this.filename = filename; this.info = info; this.indexer = indexer; file = new TileDataFile( filename, info, FileAccess.Read ); readthread = new ProcessingThread<ReadState>( LoadPage, PageLoadComplete ); }
private void ShutdownProcessingThread() { if (null != this.processingThread) { var temp = this.processingThread; this.processingThread = null; temp.BeginInvokeShutdown(); } // We're shut down - no need for this callback at this point. this.Dispatcher.ShutdownStarted -= this.Dispatcher_ShutdownStarted; }
public void Close() { if (!IsOpen) { throw new InvalidOperationException("Cannot close, is not open"); } _reconnectThread.Dispose(); _reconnectThread = null; OnClose(); CloseSocket(); IsOpen = false; IsConnected = false; Log.Debug("Socket connected to {HostName}:{Port} has been closed", _hostName, _port); }
private void timer1_Tick(object sender, EventArgs e) { if (status != null) { try { status.LogHeartbeat(this.Text); } catch (Exception ex) { // Logger.Instance.WriteToLog(ex.ToString()); } } if (ProcessingThread.IsBusy == false) { automation3List1.refreshGrid(); ProcessingThread.RunWorkerAsync(); } }
/// <summary> /// Called by OnStop of the Service, to halt current processing. /// </summary> public void StopProcessing() { try { ThreadStopping = true; if (ProcessingThread != null) { ProcessingThread.Join(StopProcessingTimeOut); // Give it up to 5 minutes to finish. } LogEvent("Processing thread stopped."); Trace.WriteLine("Stopped thread: " + ProcessingThread.Name); } catch (Exception ex) { try { string err = string.Format("Error in StopProcessing(). {0}{1}", Environment.NewLine, ex.ToFullString()); LogErrorEvent(err); Trace.WriteLine(err); } catch { } } }
public bool Open() { if (IsOpen) { throw new InvalidOperationException("Cannot open, already open"); } // Try to create socket if (!TryCreateSocket()) { return(false); } _reconnectThread = new ProcessingThread($"Socket Reconnect Thread (port {_port})", ReconnectIteration); OnOpen(); // Initial state IsOpen = true; IsConnected = false; _reconnectThread.Start(); return(true); }
public void automate() { if (status != null) { try { //status.LogHeartbeat(this.Text); } catch (Exception ex) { // Logger.Instance.WriteToLog(ex.ToString()); } } List <int> apptIDs = new List <int>(); /*********************** get appointments to automate ********************/ SqlDataReader reader; string CustomAutomationString = Configurator.getNodeValue("DatabaseInfo", "AUTOMATION_SQL"); if (string.IsNullOrEmpty(CustomAutomationString) == false) { reader = BCDB2.Instance.ExecuteReader(CustomAutomationString); } else { reader = BCDB2.Instance.ExecuteReaderSPWithParams("sp_Automation", null); } try { while (reader.Read()) { if (reader.IsDBNull(0) == false) { apptIDs.Add(reader.GetInt32(0)); } } } catch (Exception e) { Logger.Instance.WriteToLog("Error getting appointment IDs: " + e.ToString()); } finally { if (reader != null) { reader.Close(); } } if (apptIDs.Count == 0) { ProcessingThread.ReportProgress(0, "No appointments are marked for automation - " + DateTime.Now.ToString()); return; } /*********************** automation cycle ********************/ foreach (int apptid in apptIDs) { if (ProcessingThread.CancellationPending) { return; } ProcessingThread.ReportProgress(0, "Running automation for appt: " + apptid.ToString() + "."); /*********************** Get Unitnum & set active patient ********************/ string unitnum = ""; ParameterCollection pc = new ParameterCollection("apptID", apptid); using (reader = BCDB2.Instance.ExecuteReaderSPWithParams("sp_3_GetUnitnum", pc)) //ExecuteReader("SELECT unitnum FROM tblAppointments WHERE apptID = " + apptid)) { if (reader != null && reader.Read()) { unitnum = reader.GetValue(0).ToString(); } } //StatusReport sr = new StatusReport(); //sr.apptid = apptid; //sr.description = "Started Automation cycle"; //ProcessingThread.ReportProgress(300, sr); //StatusReport sr = (StatusReport)e.UserState; //if (status != null) //{ try { //temp debug //status.LogStatus(this.Text, // "Automation", // "Ok", // "tarted Automation cycle " + apptid.ToString()); } catch (Exception ex) { Logger.Instance.WriteToLog(ex.ToString()); } //} SessionManager.Instance.SetActivePatientNoCallback(unitnum, (int)apptid); /*********************** Risk Calculations ********************/ try { ProcessingThread.ReportProgress(1, "Running risk calculations for appointment: " + apptid.ToString() + "."); SessionManager.Instance.GetActivePatient().RecalculateRisk(); } catch (Exception e) { ProcessingThread.ReportProgress(1, "Risk calculations FAILED for appointment: " + apptid.ToString() + ". " + e.ToString()); } /*********************** Update BigQueue ********************/ try { ProcessingThread.ReportProgress(1, "Updating BigQueue for appointment: " + apptid.ToString() + "."); pc = new ParameterCollection("unitnum", unitnum); BCDB2.Instance.RunSPWithParams("sp_3_populateBigQueue", pc); } catch (Exception e) { ProcessingThread.ReportProgress(1, "Updating BigQueue FAILED for appointment: " + apptid.ToString() + ". " + e.ToString()); } /*********************** Process Queue Documents ********************/ ProcessingThread.ReportProgress(1, "Processing Queue Documents for appointment: " + apptid.ToString() + "."); pc = new ParameterCollection("apptID", apptid); BCDB2.Instance.RunSPWithParams("sp_processQueueDocuments", pc); /*********************** Process Automation Save Documents ********************/ ProcessingThread.ReportProgress(1, "Processing Auto Save Documents: " + apptid.ToString() + "."); ApptUtils.saveAutomationDocumentsToPrintQueue(apptid); /*********************** Run Automation Stored Procedures ********************/ ProcessingThread.ReportProgress(1, "Run Automation Stored Procedures : " + apptid.ToString() + "."); ApptUtils.runAutomationStoredProcedures(apptid); /*********************** export HL7 files ********************/ ProcessingThread.ReportProgress(1, "Export HL7 File: " + apptid.ToString() + "."); RiskService.exportHL7File(apptid); /*********************** Print Documents ********************/ try { ProcessingThread.ReportProgress(1, "Printing documents for appointment: " + apptid.ToString() + "."); ParameterCollection printDocArgs = new ParameterCollection(); printDocArgs.Add("apptid", apptid); reader = BCDB2.Instance.ExecuteReaderSPWithParams("sp_AutomationHtmlDocsToPrint", printDocArgs); int templateID = -1; string printer = ""; while (reader.Read()) { if (reader.IsDBNull(0) == false) { templateID = reader.GetInt32(0); } if (reader.IsDBNull(1) == false) { printer = reader.GetString(1); } if (templateID > 0) { if (string.IsNullOrEmpty(printer) == false) { if (printer.ToUpper() != "NO_PRINT") { ProcessingThread.ReportProgress(1, "Printing templateID " + templateID.ToString() + " for apptID " + apptid.ToString() + "."); HtmlDocument hdoc = new HtmlDocument(templateID, unitnum, apptid); hdoc.targetPrinter = printer; hdoc.apptid = apptid; htmlInProgress = true; //try //{ // ////temp debug // //status.LogStatus(this.Text, // // "Automation", // // "Ok", // // "Appt " + hdoc.apptid.ToString() + " Sent doc " + hdoc.template.documentTemplateID.ToString() + " to " + hdoc.targetPrinter); //} //catch (Exception ex) { Logger.Instance.WriteToLog(ex.ToString()); } if (status != null) { try { status.LogStatus(this.Text, "Automation", "Ok", "Appt " + hdoc.apptid.ToString() + " Sent doc " + hdoc.template.documentTemplateID.ToString() + " to " + hdoc.targetPrinter); } catch (System.Web.Services.Protocols.SoapException e) { //do nothing } catch (Exception ex) { Logger.Instance.WriteToLog(ex.ToString()); } } ProcessingThread.ReportProgress(100, hdoc); while (htmlInProgress) { Thread.Sleep(100); } string sqlStr = "INSERT INTO tblDocuments([apptID],[documentTemplateID],[created],[createdBy]) VALUES(" + hdoc.apptid.ToString() + "," + hdoc.template.documentTemplateID + "," + "'" + DateTime.Now + "','AUTOMATION');"; BCDB2.Instance.ExecuteNonQuery(sqlStr); } } } } } catch (Exception e) { ProcessingThread.ReportProgress(1, "Printing FAILED for appointment: " + apptid.ToString() + ". " + e.ToString()); } finally { if (reader != null) { reader.Close(); } } /*********************** Mark as printed to complete automation ********************/ try { String sqlStr = "UPDATE tblRiskData SET printed = 1 WHERE apptid = " + apptid.ToString() + ";"; BCDB2.Instance.ExecuteNonQuery(sqlStr); } catch (Exception e) { ProcessingThread.ReportProgress(1, ("Automation - unable to update appt id=" + apptid.ToString() + " printed=1.\n" + e.ToString())); } ProcessingThread.ReportProgress(200, ""); } }
private void MainWindow_Loaded(object sender, RoutedEventArgs e) { sensor = KinectSensor.GetDefault(); if (sensor != null) { // don't want to turn it off anymore // using it to create reflection //try //{ // sensor.ForceInfraredEmitterOff = true; //} //catch (Exception) //{ // Console.WriteLine("You can't turn off the infrared emitter on XBOX Kinect"); //} irReader = sensor.DepthFrameSource.OpenReader(); irReader.FrameArrived += irReader_FrameArrived; var fd = irReader.DepthFrameSource.FrameDescription; irBuffer = new ushort[fd.LengthInPixels]; irPixels = new byte[fd.LengthInPixels * 4]; irBitmap = new WriteableBitmap(this.irReader.DepthFrameSource.FrameDescription.Width, this.irReader.DepthFrameSource.FrameDescription.Height, 96.0, 96.0, PixelFormats.Gray8, null); this.Dispatcher.ShutdownStarted += this.Dispatcher_ShutdownStarted; LoadSettingsFromFile(); //BlobsImage.Source = irBitmap; //sensor.AllFramesReady += sensor_AllFramesReady; //_detector = new FGDetector<Bgr>(FORGROUND_DETECTOR_TYPE.FGD); //_tracker = new BlobTrackerAuto<Bgr>(); // Setup osc sender oscArgs[0] = TbIpAddress.Text; oscArgs[1] = TbPortNumber.Text; oscWriter = new UdpWriter(oscArgs[0], Convert.ToInt32(oscArgs[1])); //oscWriter.Dispose(); //oscWriter = new UdpWriter(oscArgs[0], Convert.ToInt32(oscArgs[1])); timer = new Timer(); timer.Interval = 4000; timer.Elapsed += TimerOnElapsed; this.processingThread = new ProcessingThread(sensor, this.irReader_FrameArrived); try { sensor.Open(); } catch (IOException) { sensor = null; } } if (sensor == null) { //outputViewbox.Visibility = System.Windows.Visibility.Collapsed; txtMessage.Text = "No Kinect Found.\nPlease plug in Kinect\nand restart this application."; } }
protected override void OnClose() { _receiveThread?.Dispose(); _receiveThread = null; }
protected override void OnOpen() { _receiveThread = new ProcessingThread($"Socket Receive Thread (port {_port})", ReceiveIteration); }