CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2006
    Posts
    306

    [RESOLVED] Process Closes On Open, Doesn't Trigger Process.Exit

    Alright, so I made a process to start a 3D game (Worms 4: Mayhem). I first tried it in a console application, and it started the process, and then it got closed. I thought it was just because I was ina console application, so I tried it in a WinApp. Same result.

    I also tried pre-pending an "explorer.exe" to the games .exe file (in the process' path string), so explorer would actually run it instead of my program. Again, same result. Also, it doesn't trigger the Process.Exit event.

    Does it have to do with the fact that it's a 3D game with DirectX and stuff?

    Can I get some help or maybe some workaround? I can't really have a modding editor/program if I can't run the main game.

  2. #2
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Process Closes On Open, Doesn't Trigger Process.Exit

    Well, your video game would be in a constant loop, so you must be doing something to exit the application. A WinForms application closes when the main form closes or if you do it programmatically. Not much else to say without seeing some code.

  3. #3
    Join Date
    May 2006
    Posts
    306

    Re: Process Closes On Open, Doesn't Trigger Process.Exit

    Oh, I got it fixed.

    I used a using block, and everything fine now.

    Code:
    ProcessStartInfo startInfo = new ProcessStartInfo();
    startInfo.WorkingDirectory = "Path/To/Game"
            startInfo.FileName = "Worms 4 Mayhem.exe";
            try
            {
                // Start the process with the info we specified.
                // Call WaitForExit and then the using statement will close.
                using (Process exeProcess = Process.Start(startInfo))
                {
                    exeProcess.WaitForExit();
                }
            }
            catch
            {
                // Log error.
            }
    This works.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured