protected override void OnClosing(CancelEventArgs e) { //keep this running on main thread, otherwise it will terminated before the task is done. this.Hide(); searchPanel?.Close(); chromaTimer?.Dispose(); //defaultAudioEndpointTimer?.Dispose(); wallpaper?.Dispose(); player?.Dispose(); chroma?.Dispose(); OutputDevice.ActiveDevice?.Dispose(); base.OnClosing(e); }