From 5caebf2b3486427daf71106673af123b2e9c1b74 Mon Sep 17 00:00:00 2001 From: Pariring Date: Wed, 9 Nov 2022 21:54:39 +0900 Subject: [PATCH] feat: use ManualResetEvent instead of loop --- Runtime/SkyHookManager.cs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Runtime/SkyHookManager.cs b/Runtime/SkyHookManager.cs index 3ceb009..7e03eb3 100644 --- a/Runtime/SkyHookManager.cs +++ b/Runtime/SkyHookManager.cs @@ -13,6 +13,8 @@ namespace SkyHook { private static SkyHookManager _instance; + private ManualResetEvent _mre; + /// /// Whether this process is focused. /// @@ -77,6 +79,8 @@ namespace SkyHook var started = false; Exception exception = null; + _mre = new(false); + new Thread(() => { try @@ -91,9 +95,7 @@ namespace SkyHook isHookActive = true; started = true; - while (isHookActive) - { - } + _mre.WaitOne(); } catch (Exception e) { @@ -121,6 +123,11 @@ namespace SkyHook throw new SkyHookException(result); } + if (_mre != null) + { + _mre.Set(); + } + isHookActive = false; } @@ -136,7 +143,7 @@ namespace SkyHook Debug.LogWarning("You may not call StartHook() if the application is not playing."); return; } - + Instance._StartHook(); } @@ -169,4 +176,4 @@ namespace SkyHook } } } -} +} \ No newline at end of file