private void AppWindow_FormClosing(object sender, FormClosingEventArgs e) { if (Recorder.IsRecording) { switch (MessageBox.Show("Recording not saved. Discard?", "Recording in progress!", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)) { case DialogResult.Cancel: e.Cancel = true; return; case DialogResult.OK: Recorder.Cancel(); break; } } AudioDevice.Close(); }