private void DoAcq(WorkParameters args, IProgress <ProgressObject> progress, CancellationToken cancel) { LastAcqWidth = Camera.AcqWidth; LastVBin = Camera.Image.vbin; int[] DataBuffer = new int[Camera.AcqSize]; for (int i = 0; i < args.NScans; i++) { if (args.ReadMethod == "GetAcquiredData") { LastStatus = Camera.Acquire(DataBuffer); } else { LastStatus = CameraAs <AndorCamera>().AcquireImage(DataBuffer); } RawData.WriteNext(DataBuffer, 0); progress.Report(new ProgressObject() { CurrentScan = i, Data = (int[])DataBuffer.Clone() }); DoPause(); if (cancel.IsCancellationRequested) { return; } } }
private void DoCapture(WorkParameters args, IProgress <ProgressObject> progress, CancellationToken cancel) { InitDataFile(Camera.AcqSize, args.NScans); if (args.Excite) { Flags.OpenLaserAndFlash(); } else { Flags.OpenFlash(); } DoAcq(args, progress, cancel); Flags.CloseLaserAndFlash(); }
private async void darkButton_Click(object sender, EventArgs e) { TaskStart(); var progress = new Progress <ProgressObject>(ReportProgress); var args = new WorkParameters() { ReadMethod = (string)AcqMethods.SelectedItem, NScans = (int)NScans.Value }; Work = DoWorkAsync(DoDark, args, progress, WorkCts.Token); await Work; TaskFinish(); }
private void UpdateDetailDisplay(string variableName) { if (worker == null) { worker = new BackgroundWorker(); worker.WorkerSupportsCancellation = true; worker.WorkerReportsProgress = false; worker.DoWork += new DoWorkEventHandler(worker_DoWork); worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted); } else if (worker.WorkerSupportsCancellation && worker.CancellationPending) { worker.CancelAsync(); } WorkParameters parameters = new WorkParameters(); parameters.VariableName = variableName; parameters.DataType = DashboardHelper.GetColumnType(variableName); parameters.Worker = worker; worker.RunWorkerAsync(parameters); }
void worker_DoWork(object sender, DoWorkEventArgs e) { WorkParameters parameters = (WorkParameters)(e.Argument); string varName = parameters.VariableName; string dataType = parameters.DataType; double count = 0; DataView dv = DashboardHelper.GenerateView(); switch (dataType) { case "System.String": // do nothing break; case "System.Byte": case "System.Int16": case "System.Int32": case "System.Int64": case "System.Single": case "System.Double": case "System.Decimal": double min = Double.NaN; double max = Double.NaN; double mean = Double.NaN; double sum = Double.NaN; count = 0; foreach (DataRowView rowView in dv) { DataRow row = rowView.Row; if (row[varName] != DBNull.Value) { double value = Convert.ToDouble(row[varName]); if (value > max || Double.IsNaN(max)) { max = value; } if (value < min || Double.IsNaN(min)) { min = value; } if (Double.IsNaN(sum)) { sum = value; } else { sum = sum + value; } count++; } if (worker.WorkerSupportsCancellation && worker.CancellationPending) { e.Result = null; return; } } mean = sum / count; NumericResults numericResults = new NumericResults(); numericResults.WorkParameters = parameters; numericResults.Max = max; numericResults.Min = min; numericResults.Sum = sum; numericResults.Mean = mean; if (worker.WorkerSupportsCancellation && !worker.CancellationPending) { e.Result = numericResults; return; } break; case "System.DateTime": DateTime?minDate = null; DateTime?maxDate = null; foreach (DataRowView rowView in dv) { DataRow row = rowView.Row; if (row[varName] != DBNull.Value) { DateTime value = (DateTime)row[varName]; if (!maxDate.HasValue || value > maxDate.Value) { maxDate = value; } if (!minDate.HasValue || value < minDate.Value) { minDate = value; } } if (worker.WorkerSupportsCancellation && worker.CancellationPending) { e.Result = null; return; } } DateResults dateResults = new DateResults(); dateResults.WorkParameters = parameters; dateResults.Max = maxDate; dateResults.Min = minDate; if (worker.WorkerSupportsCancellation && !worker.CancellationPending) { e.Result = dateResults; return; } break; case "System.Boolean": int t = 0; int f = 0; count = 0; foreach (DataRowView rowView in dv) { DataRow row = rowView.Row; if (row[varName] != DBNull.Value) { bool value = Convert.ToBoolean(row[varName]); if (value == true) { t = t + 1; } else if (value == false) { f = f + 1; } } if (worker.WorkerSupportsCancellation && worker.CancellationPending) { e.Result = null; return; } count++; } BooleanResults booleanResults = new BooleanResults(); booleanResults.WorkParameters = parameters; booleanResults.True = t; booleanResults.False = f; if (count > 0) { if (booleanResults.True.HasValue) { booleanResults.TruePercent = booleanResults.True / count; } if (booleanResults.False.HasValue) { booleanResults.FalsePercent = booleanResults.False / count; } } if (worker.WorkerSupportsCancellation && !worker.CancellationPending) { e.Result = booleanResults; return; } break; } }
private void DoDark(WorkParameters args, IProgress <ProgressObject> progress, CancellationToken cancel) { InitDataFile(Camera.AcqSize, args.NScans); Flags.CloseLaserAndFlash(); DoAcq(args, progress, cancel); }
private async Task DoWorkAsync(Action <WorkParameters, IProgress <ProgressObject>, CancellationToken> func, WorkParameters args, IProgress <ProgressObject> progress, CancellationToken cancel) { await Task.Run(() => func(args, progress, cancel)); }