From 0896f044e8bd225330db42864f422e0cf1ed2d7e Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Fri, 24 Aug 2018 17:35:57 -0500 Subject: [PATCH] Fixed problem with unplugging controllers causing cross thread problems --- DS4Windows/DS4Control/ControlService.cs | 7 +++++-- DS4Windows/DS4Forms/DS4Form.cs | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/DS4Windows/DS4Control/ControlService.cs b/DS4Windows/DS4Control/ControlService.cs index 0994918..bf12f13 100644 --- a/DS4Windows/DS4Control/ControlService.cs +++ b/DS4Windows/DS4Control/ControlService.cs @@ -1047,8 +1047,11 @@ namespace DS4Windows lag[ind] = false; inWarnMonitor[ind] = false; useDInputOnly[ind] = true; - OnControllerRemoved(this, ind); - Thread.Sleep(XINPUT_UNPLUG_SETTLE_TIME); + uiContext?.Post(new SendOrPostCallback((state) => + { + OnControllerRemoved(this, ind); + }), null); + //Thread.Sleep(XINPUT_UNPLUG_SETTLE_TIME); } } } diff --git a/DS4Windows/DS4Forms/DS4Form.cs b/DS4Windows/DS4Forms/DS4Form.cs index 6ae5f7f..21f57cf 100644 --- a/DS4Windows/DS4Forms/DS4Form.cs +++ b/DS4Windows/DS4Forms/DS4Form.cs @@ -2174,14 +2174,15 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question FormLocationX = Location.X > 0 ? Location.X : 0; FormLocationY = Location.Y > 0 ? Location.Y : 0; + Global.ControllerRemoved -= ControllerRemovedChange; if (!string.IsNullOrEmpty(appdatapath)) { Save(); blankControllerTab(); - Program.rootHub.Stop(); } + TaskRunner.Run(() => Program.rootHub.Stop()).Wait(); // Make sure to stop event generation routines. Should fix odd crashes on shutdown Application.Exit(); }