mirror of
https://github.com/cemu-project/DS4Windows.git
synced 2024-12-24 15:41:49 +01:00
Remove ui thread from unplug routine
Hotplug routine was starting before removal routine was being started. No blocking was happening anyway
This commit is contained in:
parent
ac9e2411ac
commit
6f5b17ac37
@ -381,6 +381,7 @@ namespace DS4Windows
|
||||
return unplugResult;
|
||||
}
|
||||
|
||||
private SynchronizationContext uiContext = null;
|
||||
public bool Start(object tempui, bool showlog = true)
|
||||
{
|
||||
if (x360Bus.Open() && x360Bus.Start())
|
||||
@ -391,6 +392,7 @@ namespace DS4Windows
|
||||
LogDebug("Connection to Scp Virtual Bus established");
|
||||
|
||||
DS4Devices.isExclusiveMode = getUseExclusiveMode();
|
||||
uiContext = tempui as SynchronizationContext;
|
||||
if (showlog)
|
||||
{
|
||||
LogDebug(Properties.Resources.SearchingController);
|
||||
@ -424,7 +426,6 @@ namespace DS4Windows
|
||||
task.Start();
|
||||
|
||||
DS4Controllers[i] = device;
|
||||
device.setUiContext(tempui as SynchronizationContext);
|
||||
device.Removal += this.On_DS4Removal;
|
||||
device.Removal += DS4Devices.On_Removal;
|
||||
device.SyncChange += this.On_SyncChange;
|
||||
@ -618,7 +619,7 @@ namespace DS4Windows
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool HotPlug(SynchronizationContext uiContext)
|
||||
public bool HotPlug()
|
||||
{
|
||||
if (running)
|
||||
{
|
||||
@ -655,7 +656,6 @@ namespace DS4Windows
|
||||
Task task = new Task(() => { Thread.Sleep(5); WarnExclusiveModeFailure(device); });
|
||||
task.Start();
|
||||
DS4Controllers[Index] = device;
|
||||
device.setUiContext(uiContext);
|
||||
device.Removal += this.On_DS4Removal;
|
||||
device.Removal += DS4Devices.On_Removal;
|
||||
device.SyncChange += this.On_SyncChange;
|
||||
@ -1072,7 +1072,7 @@ namespace DS4Windows
|
||||
string devError = tempStrings[ind] = device.error;
|
||||
if (!string.IsNullOrEmpty(devError))
|
||||
{
|
||||
device.getUiContext()?.Post(new SendOrPostCallback(delegate (object state)
|
||||
uiContext?.Post(new SendOrPostCallback(delegate (object state)
|
||||
{
|
||||
LogDebug(devError);
|
||||
}), null);
|
||||
@ -1084,7 +1084,7 @@ namespace DS4Windows
|
||||
if (!lag[ind] && device.Latency >= flashWhenLateAt)
|
||||
{
|
||||
lag[ind] = true;
|
||||
device.getUiContext()?.Post(new SendOrPostCallback(delegate (object state)
|
||||
uiContext?.Post(new SendOrPostCallback(delegate (object state)
|
||||
{
|
||||
LagFlashWarning(ind, true);
|
||||
}), null);
|
||||
@ -1092,7 +1092,7 @@ namespace DS4Windows
|
||||
else if (lag[ind] && device.Latency < flashWhenLateAt)
|
||||
{
|
||||
lag[ind] = false;
|
||||
device.getUiContext()?.Post(new SendOrPostCallback(delegate (object state)
|
||||
uiContext?.Post(new SendOrPostCallback(delegate (object state)
|
||||
{
|
||||
LagFlashWarning(ind, false);
|
||||
}), null);
|
||||
@ -1115,7 +1115,7 @@ namespace DS4Windows
|
||||
if (device.firstReport && device.IsAlive())
|
||||
{
|
||||
device.firstReport = false;
|
||||
device.getUiContext()?.Post(new SendOrPostCallback(delegate (object state)
|
||||
uiContext?.Post(new SendOrPostCallback(delegate (object state)
|
||||
{
|
||||
OnDeviceStatusChanged(this, ind);
|
||||
}), null);
|
||||
@ -1124,7 +1124,7 @@ namespace DS4Windows
|
||||
{
|
||||
byte tempBattery = currentBattery[ind] = cState.Battery;
|
||||
bool tempCharging = charging[ind] = device.isCharging();
|
||||
device.getUiContext()?.Post(new SendOrPostCallback(delegate (object state)
|
||||
uiContext?.Post(new SendOrPostCallback(delegate (object state)
|
||||
{
|
||||
OnBatteryStatusChange(this, ind, tempBattery, tempCharging);
|
||||
}), null);
|
||||
|
@ -1010,11 +1010,10 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question
|
||||
hotplugCounter++;
|
||||
}
|
||||
|
||||
var uiContext = SynchronizationContext.Current;
|
||||
if (!inHotPlug)
|
||||
{
|
||||
inHotPlug = true;
|
||||
TaskRunner.Run(() => { Thread.Sleep(1500); InnerHotplug2(uiContext); });
|
||||
TaskRunner.Run(() => { Thread.Sleep(1500); InnerHotplug2(); });
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1028,7 +1027,7 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question
|
||||
base.WndProc(ref m);
|
||||
}
|
||||
|
||||
private void InnerHotplug2(SynchronizationContext uiContext)
|
||||
private void InnerHotplug2()
|
||||
{
|
||||
inHotPlug = true;
|
||||
|
||||
@ -1040,7 +1039,7 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question
|
||||
|
||||
while (loopHotplug == true)
|
||||
{
|
||||
Program.rootHub.HotPlug(uiContext);
|
||||
Program.rootHub.HotPlug();
|
||||
//TaskRunner.Run(() => { Program.rootHub.HotPlug(uiContext); });
|
||||
lock (hotplugCounterLock)
|
||||
{
|
||||
|
@ -392,16 +392,6 @@ namespace DS4Windows
|
||||
return result;
|
||||
}
|
||||
|
||||
private SynchronizationContext uiContext = null;
|
||||
public SynchronizationContext getUiContext()
|
||||
{
|
||||
return uiContext;
|
||||
}
|
||||
public void setUiContext(SynchronizationContext uiContext)
|
||||
{
|
||||
this.uiContext = uiContext;
|
||||
}
|
||||
|
||||
private Queue<Action> eventQueue = new Queue<Action>();
|
||||
private object eventQueueLock = new object();
|
||||
|
||||
@ -808,10 +798,7 @@ namespace DS4Windows
|
||||
sendOutputReport(true, true); // Kick Windows into noticing the disconnection.
|
||||
StopOutputUpdate();
|
||||
isDisconnecting = true;
|
||||
uiContext.Send(new SendOrPostCallback(delegate (object state4)
|
||||
{
|
||||
Removal?.Invoke(this, EventArgs.Empty);
|
||||
}), null);
|
||||
|
||||
timeoutExecuted = true;
|
||||
return;
|
||||
@ -838,10 +825,7 @@ namespace DS4Windows
|
||||
|
||||
StopOutputUpdate();
|
||||
isDisconnecting = true;
|
||||
uiContext.Send(new SendOrPostCallback(delegate (object state4)
|
||||
{
|
||||
Removal?.Invoke(this, EventArgs.Empty);
|
||||
}), null);
|
||||
|
||||
timeoutExecuted = true;
|
||||
return;
|
||||
@ -1291,11 +1275,8 @@ namespace DS4Windows
|
||||
IsDisconnecting = true;
|
||||
|
||||
if (callRemoval)
|
||||
{
|
||||
uiContext.Send(new SendOrPostCallback(delegate (object state)
|
||||
{
|
||||
Removal?.Invoke(this, EventArgs.Empty);
|
||||
}), null);
|
||||
|
||||
//System.Threading.Tasks.Task.Factory.StartNew(() => { Removal?.Invoke(this, EventArgs.Empty); });
|
||||
}
|
||||
@ -1327,10 +1308,7 @@ namespace DS4Windows
|
||||
{
|
||||
isDisconnecting = true;
|
||||
|
||||
uiContext.Send(new SendOrPostCallback(delegate (object state4)
|
||||
{
|
||||
Removal?.Invoke(this, EventArgs.Empty);
|
||||
}), null);
|
||||
|
||||
//System.Threading.Tasks.Task.Factory.StartNew(() => { Removal?.Invoke(this, EventArgs.Empty); });
|
||||
//Removal?.Invoke(this, EventArgs.Empty);
|
||||
|
Loading…
Reference in New Issue
Block a user