mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 19:26:39 +02:00
[MWB] Remove Thread.Suspend API usage, because it always results in PlatformNotSupportedException (#29746)
This commit is contained in:
@@ -85,28 +85,6 @@ namespace MouseWithoutBorders
|
|||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void SuspendAllThreadsBut(int threadId)
|
|
||||||
{
|
|
||||||
lock (ThreadsLock)
|
|
||||||
{
|
|
||||||
#pragma warning disable 618 // Temporary
|
|
||||||
threads.Where(t => t.IsAlive && t.ManagedThreadId != threadId).ToList().ForEach(
|
|
||||||
t =>
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
t.Suspend();
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
// This method is suspending every thread so that it can kill the process right after restarting.
|
|
||||||
// Makes no sense to crash on a thread suspension fail, since we're killing the process afterwards, anyway.
|
|
||||||
}
|
|
||||||
});
|
|
||||||
#pragma warning restore 618
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void SetApartmentState(ApartmentState apartmentState)
|
internal void SetApartmentState(ApartmentState apartmentState)
|
||||||
{
|
{
|
||||||
thread.SetApartmentState(apartmentState);
|
thread.SetApartmentState(apartmentState);
|
||||||
|
|||||||
@@ -349,8 +349,6 @@ namespace MouseWithoutBorders
|
|||||||
_ = Process.Start(Application.ExecutablePath, desktop);
|
_ = Process.Start(Application.ExecutablePath, desktop);
|
||||||
LogDebug($"Started on desktop {desktop}");
|
LogDebug($"Started on desktop {desktop}");
|
||||||
|
|
||||||
Thread.SuspendAllThreadsBut(Thread.CurrentThread.ManagedThreadId);
|
|
||||||
|
|
||||||
Process.GetCurrentProcess().KillProcess(true);
|
Process.GetCurrentProcess().KillProcess(true);
|
||||||
},
|
},
|
||||||
$"{actionName} watchdog").Start();
|
$"{actionName} watchdog").Start();
|
||||||
|
|||||||
Reference in New Issue
Block a user