File tree Expand file tree Collapse file tree 1 file changed +26
-7
lines changed
Expand file tree Collapse file tree 1 file changed +26
-7
lines changed Original file line number Diff line number Diff line change @@ -381,6 +381,12 @@ private void startProcess(string name)
381381 process . StartInfo = startInfo ;
382382 process . Start ( ) ;
383383 // Directory.SetCurrentDirectory(oldCurDir);
384+
385+ // Cleaning up
386+ startInfo = null ;
387+ process . Dispose ( ) ;
388+ process = null ;
389+ GC . Collect ( ) ;
384390 }
385391
386392 private void closeProcess ( string name )
@@ -390,18 +396,31 @@ private void closeProcess(string name)
390396 int procCount = processes . Length ;
391397 if ( procCount > 0 )
392398 {
393- for ( int i = 0 ; i < procCount ; i ++ )
399+ try
394400 {
395- Console . WriteLine ( "\t " + Path . GetDirectoryName ( processes [ i ] . Modules [ 0 ] . FileName ) ) ;
396- // Close only process that exists aside program
397- bool isHLDS = name . Contains ( "hlds" ) ;
398- bool bSamePath = Path . GetDirectoryName ( processes [ i ] . Modules [ 0 ] . FileName ) . Equals ( isHLDS ? gamePath + "\\ bin" : gamePath ) ;
399- if ( bSamePath )
401+ for ( int i = 0 ; i < procCount ; i ++ )
400402 {
401- processes [ i ] . Kill ( ) ;
403+ // Console.WriteLine("\t" + Path.GetDirectoryName(processes[i].Modules[0].FileName));
404+ // Close only process that exists aside program
405+ bool isHLDS = name . Contains ( "hlds" ) ;
406+ bool bSamePath = Path . GetDirectoryName ( processes [ i ] . Modules [ 0 ] . FileName ) . Equals ( isHLDS ? gamePath + "\\ bin" : gamePath ) ;
407+ if ( bSamePath )
408+ {
409+ processes [ i ] . Kill ( ) ;
410+ processes [ i ] . Close ( ) ;
411+ processes [ i ] . Dispose ( ) ;
412+ }
402413 }
403414 }
415+ catch ( Exception ex )
416+ {
417+ Console . WriteLine ( ex . Message ) ;
418+ }
404419 }
420+
421+ // Cleaning up
422+ processes = null ;
423+ GC . Collect ( ) ;
405424 }
406425
407426 private void gameStartButton_Click ( object sender , EventArgs e )
You can’t perform that action at this time.
0 commit comments