public void StartExposure(short iso, double durationSeconds, double minDurationForBulbMode) { if (IsConnected == false) { throw new ASCOM.NotConnectedException(); } if (exposureInProgress) { throw new ASCOM.InvalidOperationException("Exposure already in progress"); } _exposureBackgroundWorker = new BackgroundWorker() { WorkerReportsProgress = false, WorkerSupportsCancellation = true }; _exposureBackgroundWorker.DoWork += new DoWorkEventHandler(((sender, args) => { SetShutterSpeed(durationSeconds, minDurationForBulbMode); SetISO(iso); SyncSaveFolder(); if (args.Cancel == false) { try { BeginExposure(); if (durationSeconds >= minDurationForBulbMode) { Thread.Sleep((int)(durationSeconds * 1000)); } if (args.Cancel == false) { EndExposure(durationSeconds >= minDurationForBulbMode); //we dont call EndExposure in case if background worker cancelled as we assume it has been already ended _fileSystemWatcher.EnableRaisingEvents = true; } } finally { lock (_lock) { exposureInProgress = false; } } } })); _exposureBackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(((sender, args) => { if (args.Cancelled == false) { ExposureCompleted?.Invoke(this, new ExposureCompletedEventArgs()); } })); _exposureBackgroundWorker.RunWorkerAsync(); }
public void StopExposure() { EndExposure(true); _fileSystemWatcher.EnableRaisingEvents = true; if (_exposureBackgroundWorker != null && _exposureBackgroundWorker.IsBusy) { _exposureBackgroundWorker.CancelAsync(); } ExposureStopped?.Invoke(this, new ExposureStoppedEventArgs()); ExposureCompleted?.Invoke(this, new ExposureCompletedEventArgs()); }
private void _remoteApp_ExposureCompleted(object sender, ExposureCompletedEventArgs e) { ExposureCompleted?.Invoke(this, e); }