Process is terminated due to StackOverflowException Process is terminated due to StackOverflowException multithreading multithreading

Process is terminated due to StackOverflowException


Try to check callstack lenght in your code:

class Program{    static void Main(string[] args)    {        try        {            Hop();        }        catch (Exception e)        {            Console.WriteLine("Exception - {0}", e);        }    }    static void Hop()    {        CheckStackTrace();        Hip();    }    static void Hip()    {        CheckStackTrace();        Hop();    }    static void CheckStackTrace()    {        StackTrace s = new StackTrace();        if (s.FrameCount > 50)            throw new Exception("Big stack!!!!");    }}


If you are having trouble following the flow of your application's code execution, try logging the entrance of methods with a timestamp and threadid.

Also, You can't catch the exception because it is a StackOverflowException.

See msdn: "Starting with the .NET Framework version 2.0, a StackOverflowException object cannot be caught by a try-catch block and the corresponding process is terminated by default. Consequently, users are advised to write their code to detect and prevent a stack overflow. For example, if your application depends on recursion, use a counter or a state condition to terminate the recursive loop. "


Do you utlize any heavy-weight library for tasks like DownloadNewMail and SendNewMail? For example I encountered StackOverflows when running large jobs using Microsoft.SqlServer.Dts.Runtime.Package. Try running the same workload sequentially inside a command-line application to see if the issue persists.