when c# program crash how to know why?
<p>Often my program crash by some reason. In this case I do see Windows message with "Close" button. Every time such thing happen I do really want to know what happened.</p>

<p>Thanks to community I already know how to "handle" some situations, I've added such code in the beggining of my program:</p>

<pre><code>    static void Main(string[] args)
    {
        AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

        TaskScheduler.UnobservedTaskException +=
        (object sender, UnobservedTaskExceptionEventArgs excArgs) =&gt;
        {
            Log.Push(LogItemType.Error, "Exception occured. Task terminated! + " + excArgs.Exception);
            excArgs.SetObserved();
        };

    .....

    static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
    {
        Console.WriteLine("Error: CurrentDomain_UnhandledException entered.");
        string message = (e.ExceptionObject as Exception).Message;
        Console.WriteLine(message);
        System.Diagnostics.Trace.WriteLine(message, "Unhandled UI Exception");
        Log.Push(LogItemType.Error, message);
    }
</code></pre>

<p>Sometimes this helps. But sometimes program just crash with no message. What else can I do? Every time program crash I want to know why.</p>

<p><strong>upd</strong> Windows Logs contains almost everything I need, except the most important thing - the stacktrace</p>

<pre><code>Faulting application name: MBClient.exe, version: 1.0.0.0, time stamp: 0x50a5da1d
Faulting module name: ntdll.dll, version: 6.1.7601.17725, time stamp: 0x4ec4aa8e
Exception code: 0xc0000374
Fault offset: 0x00000000000c40f2
Faulting process id: 0x10f8
Faulting application start time: 0x01cdc3c2041e2607
Faulting application path: C:\Oleg\bin\mbclient\MBClient.exe
Faulting module path: C:\Windows\SYSTEM32\ntdll.dll
Report Id: 810c805d-2fc3-11e2-bfb5-2c768a509157
</code></pre>
