feat: use ManualResetEvent instead of loop
							parent
							
								
									3dd375a1df
								
							
						
					
					
						commit
						5caebf2b34
					
				| 
						 | 
					@ -13,6 +13,8 @@ namespace SkyHook
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        private static SkyHookManager _instance;
 | 
					        private static SkyHookManager _instance;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        private ManualResetEvent _mre;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// Whether this process is focused.
 | 
					        /// Whether this process is focused.
 | 
				
			||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
| 
						 | 
					@ -77,6 +79,8 @@ namespace SkyHook
 | 
				
			||||||
            var started = false;
 | 
					            var started = false;
 | 
				
			||||||
            Exception exception = null;
 | 
					            Exception exception = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            _mre = new(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            new Thread(() =>
 | 
					            new Thread(() =>
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                try
 | 
					                try
 | 
				
			||||||
| 
						 | 
					@ -91,9 +95,7 @@ namespace SkyHook
 | 
				
			||||||
                    isHookActive = true;
 | 
					                    isHookActive = true;
 | 
				
			||||||
                    started = true;
 | 
					                    started = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    while (isHookActive)
 | 
					                    _mre.WaitOne();
 | 
				
			||||||
                    {
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                catch (Exception e)
 | 
					                catch (Exception e)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
| 
						 | 
					@ -121,6 +123,11 @@ namespace SkyHook
 | 
				
			||||||
                throw new SkyHookException(result);
 | 
					                throw new SkyHookException(result);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (_mre != null)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                _mre.Set();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            isHookActive = false;
 | 
					            isHookActive = false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Reference in New Issue