4 Replies - 443 Views - Last Post: 30 April 2013 - 05:54 AM Rate Topic: -----

#1 krazyshank  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 21-December 12

Auto end process when it "Stopped Working"

Posted 29 April 2013 - 03:10 PM

I'm making a wrapper for a server that is prone to crashes.
I've made it to where my program will auto-resart the process if it isn't running and the user specified so in the settings, however, when this server.exe crashes, a window pops up (it's a command line process) from windows saying "Server.exe has stopped working" then it gives two options, end it or debug it.

The problem is, is that when this window pops up, the process is still tecnically running so my auto-restart won't we start it (it only detects if the process is not running).

I've tried process.Responding and that's not seeming to work.

my method:
public bool Responsive()
        {
            bool rm = false;
            Process[] prs = Process.GetProcesses();
            foreach (Process pr in prs)
            {
                if (pr.ProcessName == "wServer" && pr.Responding)
                {
                    rm = true;
                }
            }
            return rm;
        }



and the timer that runs every 3 seconds to see if it's responding:
if (Responsive() == false)
                    {
                        Process[] prs = Process.GetProcesses();
                        foreach (Process pr in prs)
                        {
                            if (pr.ProcessName == "wServer")
                            {
                                pr.Kill();
                            }
                        }
                    }



Is This A Good Question/Topic? 0
  • +

Replies To: Auto end process when it "Stopped Working"

#2 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5514
  • View blog
  • Posts: 11,823
  • Joined: 02-June 10

Re: Auto end process when it "Stopped Working"

Posted 29 April 2013 - 04:47 PM

Quote

I'm making a wrapper for a server that is prone to crashes.

Fix Server.exe rather than band aide the symptom.

This course of action is about the same as "When the engine starts making that horrible noise and banging, I turn the radio up louder to fix it."
Was This Post Helpful? 0
  • +
  • -

#3 krazyshank  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 21-December 12

Re: Auto end process when it "Stopped Working"

Posted 29 April 2013 - 05:05 PM

View PosttlhIn`toq, on 29 April 2013 - 04:47 PM, said:

Quote

I'm making a wrapper for a server that is prone to crashes.

Fix Server.exe rather than band aide the symptom.

This course of action is about the same as "When the engine starts making that horrible noise and banging, I turn the radio up louder to fix it."


Server.exe isn't mine. if it was made by me it would only makes sense for me to fix it, but it isn't :(
Anyways, i've found a dirty solution and that's to end WinFault.exe (runs when sever crashes).
Upon closing that, it ends server.exe.
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3574
  • View blog
  • Posts: 11,112
  • Joined: 05-May 12

Re: Auto end process when it "Stopped Working"

Posted 29 April 2013 - 08:07 PM

I'm assuming that server is only running on that machine and you are allowed to tweak the environment since you are already doing so by changing the crash handling behavior. If that assumption is correct, you can change the AeDebug set of registry keys to point to your program instead of Visual Studio or some other debugger. That way you don't have to poll to see if the server is responsive or has crashed, just let the OS call you when it does become unresponsive or crashes.

See: http://msdn.microsof...4(v=vs.85).aspx

If you don't want anything as heavy handed as the AeDebug registry key, you can also be more targeted about which executable you want to debug, by using the gflags.exe and targetting just your server. Believe with this route, you could potentially also always have the server process running as a child of your process so that you can get debugger rights and be able to catch the crashes earlier. I've not actually tried this since I've only ever used gflags.exe to always point to windbg or Visual Studio and not a debugger of my own making.

See: http://msdn.microsof...7(v=vs.85).aspx

This post has been edited by Skydiver: 29 April 2013 - 08:18 PM

Was This Post Helpful? 3
  • +
  • -

#5 pharylon  Icon User is offline

  • D.I.C Head

Reputation: 40
  • View blog
  • Posts: 83
  • Joined: 01-September 12

Re: Auto end process when it "Stopped Working"

Posted 30 April 2013 - 05:54 AM

I like reading this forum, because even if it's not my problem, I learn a lot. Skydiver, I didn't even know what you're talking about was possible. Good info. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1