Skip to content

Detect Runtime Error from another application.

Sergio Fonseca

Asked Apr 22, 2008, 9:41 AM EDT2 answers
Share
LinkedInX
I'm making an program to keep alive an server for a game. Unlucky sometimes it gets and Runtime Error and then the server stop and my program can't detect when it happen to restart the server. So I'm in need of something to detect when another application gets an Runtime Error to be able to restart it. Thank you.

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Bechir Bejaoui
    0
    in this case you should better use the Trace or the Debug  classes and add a tracelistener into your project to establish an application journal.
    Here you an exmple of doing this add this code to your application to listen to the targeted thread or/and process

    System.IO.FileStream oStream = new System.IO.FileStream(@"C:\MyJournal.txt",FileMode.OpenOrCreate);
    TextWriterTraceLitener myListener = new TextWriterTraceLitener(oStream);

    use Debug class if your application is in debug mode:
    Debug.Listeners.Add(myListener);
    use Debug class if your application is in release mode:
    Trace.Listeners.Add(myListener);
    After excuting the application and the error happens
    move to
    C:\MyJournal.txt
    you'll find there all your application inforation process step by step
    0
  • 0
    Thank you.
    Sorry I'm new on C# how could I detect the error on run even with that? I understood that the code you sent logs everything that happens with the application but is there a way to detect them on run to restart the application?
    0