protected virtual void Dispose(bool disposing) { if (disposing) { if (_config != null) { Toml.WriteFile(_config, "config.toml", _tomlSettings); _config = null; } _waveIn?.StopRecording(); _waveIn?.Dispose(); _waveIn = null; _speechRecognizer?.Dispose(); _speechRecognizer = null; _skFont?.Dispose(); _skFont = null; _skStrokePaint?.Dispose(); _skStrokePaint = null; _skFillPaint?.Dispose(); _skFillPaint = null; _skScreenSurface?.Dispose(); _skScreenSurface = null; _skScreenRenderTarget?.Dispose(); _skScreenRenderTarget = null; _skContext?.Dispose(); _skContext = null; _skInterface?.Dispose(); _skInterface = null; _tkContext?.Dispose(); _tkContext = null; _tkWindow?.Dispose(); _tkWindow = null; } }
public async Task <bool> Confirm(string question, string positive, string negative, bool showDialog, CancellationToken?cancelToken) { var tcs = new TaskCompletionSource <bool>(); var cancelSrc = new CancellationTokenSource(); IDisposable dialog = null; IDisposable speech = null; if (showDialog) { this.dialogs.Confirm(new ConfirmConfig { Message = question, OkText = positive, CancelText = negative, OnAction = dr => { tcs.TrySetResult(dr); speech.Dispose(); cancelSrc.Cancel(); } }); } await this.tts.Speak(question, cancelToken : cancelSrc.Token); speech = this.speech .ListenForFirstKeyword(positive, negative) .Subscribe(text => { var r = text.Equals(positive, StringComparison.CurrentCultureIgnoreCase); dialog?.Dispose(); tcs.TrySetResult(r); }); cancelToken?.Register(() => { dialog?.Dispose(); speech.Dispose(); tcs.TrySetCanceled(); }); return(await tcs.Task); }