0

My goal is to isolate some code execution for NET Core.

  1. I have a console application #1 (parent?), which starts a process for another console application #2 (child?), which in turn runs dynamically compiled code.
  2. Execution of that code may result in fatal error, e.g., OutOfMemoryException.
  3. When it happens, then the application #1 fails along with the application #2.

Is there a way to save the application #1 from the fail of the application #2?

Maybe I misunderstand something, but I thought that these should be totally separate. Please help. Will appreciate a solution for NET Framework as well, if any.

        ProcessStartInfo processStartInfo = new ProcessStartInfo(filePath, processArgs)
        {
            UseShellExecute = false,
            RedirectStandardOutput = true,
            CreateNoWindow = true
        };

        using (Process process = new Process()
        {
            StartInfo = processStartInfo,
            EnableRaisingEvents = true
        })
        {
            process.Start();
            process.WaitForExit();

            return process.StandardOutput.ReadToEnd();
        };
  • 1
    What exactly happens in the parent process when the child process fails? FWIW, I would also have expected them to be independent. – 500 - Internal Server Error Oct 04 '21 at 16:12
  • What about trying to catch the exception raised by thread #2 in thread #1? – T.Trassoudaine Oct 04 '21 at 16:15
  • @500-InternalServerError, both apps are crashed and I receive windows popup about fail. – Vesper Lynd Oct 04 '21 at 16:19
  • @T.Trassoudaine, do you suggest to run application #2 from another thread? – Vesper Lynd Oct 04 '21 at 16:19
  • 1
  • No I suggest you use the try{} catch{} statement that you are supposed to use to handle Exceptions when you can't avoid the Exception. – T.Trassoudaine Oct 04 '21 at 16:23
  • @500-InternalServerError, Title: werfault.exe - application error Message: Error during application start (0xc000012d). Click OK to exit. – Vesper Lynd Oct 04 '21 at 16:26
  • FWIW, I don't think this is due to something your code does incorrectly. Possibly a virus checker issue. Is your child app really using up all available memory in this scenario? - because that can sometimes provoke failures in other parts of the system, including Windows itself (this is anecdotal "evidence", I know). – 500 - Internal Server Error Oct 04 '21 at 16:30
  • @T.Trassoudaine, most possibly I have worked for too long today :) Or have read Richter badly, because I though that this type of exception cannot be catched. You are right, try/catch block, which wraps code of the application #2, has helped. Then I wonder, if there is some kind of error which cannot be handled that way? – Vesper Lynd Oct 04 '21 at 16:36
  • https://stackoverflow.com/questions/12774975/what-kind-of-exceptions-cannot-be-handled : this probably answers your last question. – T.Trassoudaine Oct 04 '21 at 16:43

1 Answers1

0

So, wrapping up the code of the child application is enough. Parent application continues its work even after OutOfMemoryException, StackOverflowException, AccessViolationException in the child application.

Just got to keep in mind that child application may need some time to totally deallocate the resources it has used after the crash, so some of them may still be locked in parent application.

Thanks guys for eyes opening!