private void m_timer_Elapsed(object sender, ElapsedEventArgs e) { if (!Global.Dialogs.IsViewModelRegistered(this)) // check is window closed { m_timer.Stop(); return; } Global.Dialogs.GetWindow(this).Dispatcher.Invoke(new Action(() => { try { CurrentValue = m_device.GetRawAxis().Value; } catch { m_result = CallibrationResult.ErrorOccurred; if (Global.Dialogs.IsViewModelRegistered(this)) // check is window closed { m_timer.Stop(); Global.Dialogs.Close(this); return; } } if (CurrentStep == CallibrationCurrentStep.PlaceInZero) { ZeroValue = CurrentValue; } else if (CurrentStep == CallibrationCurrentStep.AveragingResult) { m_timerElapsed += TimerUpdateTime; m_averageSum += CurrentValue; m_averageCount++; if (m_timerElapsed >= AveragingTime) { ZeroValue = (int)Math.Round((double)m_averageSum / (double)m_averageCount); CurrentStep = CallibrationCurrentStep.Tilt; } } else if (CurrentStep == CallibrationCurrentStep.Tilt) { int val = CurrentValue - ZeroValue; int absVal = Math.Abs(val); if (val < 0 && absVal > MinusVariation) { MinusVariation = absVal; } else if (val >= 0 && absVal > PlusVariation) { PlusVariation = absVal; } } })); }
private void Cancel(object e) { m_result = CallibrationResult.Cancel; Global.Dialogs.Close(this); }
private void Ok(object e) { m_result = CallibrationResult.Ok; Global.Dialogs.Close(this); }