public void Stop() { if (_state == RecorderState.Stopped || _state == RecorderState.Unknown) { throw new InvalidOperationException("No recording in progress."); } if (_capture.StopCapture()) { _state = RecorderState.Stopped; _timer.Stop(); _isCapturing = false; _writer.Flush(); } _stream.Dispose(); }