@@ -2838,10 +2838,10 @@ private static void GenshinHDREnforcer()
28382838 private async Task GameBoost_Invoke ( GamePresetProperty gameProp )
28392839 {
28402840#nullable enable
2841- Process ? toTargetProc = null ;
2841+ string processName = gameProp . GameExecutableName ;
2842+ int processId = - 1 ;
28422843 try
28432844 {
2844- int processId ;
28452845 // Try catching the non-zero MainWindowHandle pointer and assign it to "toTargetProc" variable by using GetGameProcessWithActiveWindow()
28462846 while ( ! gameProp . TryGetGameProcessIdWithActiveWindow ( out processId , out _ ) )
28472847 {
@@ -2851,11 +2851,8 @@ private async Task GameBoost_Invoke(GamePresetProperty gameProp)
28512851 // which it will break the loop and execute the next code below it.
28522852 }
28532853
2854- // Init new target process
2855- toTargetProc = Process . GetProcessById ( processId ) ;
2856-
28572854 LogWriteLine ( $ "[HomePage::GameBoost_Invoke] Found target process! Waiting 10 seconds for process initialization...\r \n \t " +
2858- $ "Target Process : { toTargetProc . ProcessName } [{ toTargetProc . Id } ]", LogType . Default , true ) ;
2855+ $ "Target Process : { processName } [{ processId } ]", LogType . Default , true ) ;
28592856
28602857 // Wait 20 (or 10 if its first try) seconds before applying
28612858 if ( GameBoostInvokeTryCount == 0 )
@@ -2868,38 +2865,37 @@ private async Task GameBoost_Invoke(GamePresetProperty gameProp)
28682865 }
28692866
28702867 // Check early exit
2871- if ( toTargetProc . HasExited )
2868+ if ( ! gameProp . GetIsGameProcessRunning ( processId ) )
28722869 {
2873- LogWriteLine ( $ "[HomePage::GameBoost_Invoke] Game process { toTargetProc . ProcessName } [{ toTargetProc . Id } ] has exited!",
2870+ LogWriteLine ( $ "[HomePage::GameBoost_Invoke] Game process { processName } [{ processId } ] has exited!",
28742871 LogType . Warning , true ) ;
28752872 return ;
28762873 }
28772874
28782875 // Assign the priority to the process and write a log (just for displaying any info)
2879- toTargetProc . PriorityClass = ProcessPriorityClass . AboveNormal ;
2876+ if ( ! gameProp . TrySetGameProcessPriority ( processId , Hi3Helper . Win32 . Native . Enums . PriorityClass . ABOVE_NORMAL_PRIORITY_CLASS ) )
2877+ {
2878+ throw new Win32Exception ( ) ;
2879+ }
28802880 GameBoostInvokeTryCount = 0 ;
2881- LogWriteLine ( $ "[HomePage::GameBoost_Invoke] Game process { toTargetProc . ProcessName } " +
2882- $ "[{ toTargetProc . Id } ] priority is boosted to above normal!", LogType . Warning , true ) ;
2881+ LogWriteLine ( $ "[HomePage::GameBoost_Invoke] Game process { processName } " +
2882+ $ "[{ processId } ] priority is boosted to above normal!", LogType . Warning , true ) ;
28832883 }
28842884 catch ( Exception ex ) when ( GameBoostInvokeTryCount < 5 )
28852885 {
28862886 LogWriteLine ( $ "[HomePage::GameBoost_Invoke] (Try #{ GameBoostInvokeTryCount } )" +
28872887 $ "There has been error while boosting game priority to Above Normal! Retrying...\r \n " +
2888- $ "\t Target Process : { toTargetProc ? . ProcessName } [{ toTargetProc ? . Id } ]\r \n { ex } ",
2888+ $ "\t Target Process : { processName } [{ processId } ]\r \n { ex } ",
28892889 LogType . Error , true ) ;
28902890 GameBoostInvokeTryCount ++ ;
28912891 _ = Task . Run ( async ( ) => { await GameBoost_Invoke ( gameProp ) ; } ) ;
28922892 }
28932893 catch ( Exception ex )
28942894 {
28952895 LogWriteLine ( $ "[HomePage::GameBoost_Invoke] There has been error while boosting game priority to Above Normal!\r \n " +
2896- $ "\t Target Process : { toTargetProc ? . ProcessName } [{ toTargetProc ? . Id } ]\r \n { ex } ",
2896+ $ "\t Target Process : { processName } [{ processId } ]\r \n { ex } ",
28972897 LogType . Error , true ) ;
28982898 }
2899- finally
2900- {
2901- toTargetProc ? . Dispose ( ) ;
2902- }
29032899#nullable restore
29042900 }
29052901 #endregion
0 commit comments