C#.NET 4.0应用程序随机崩溃 [英] C# .NET 4.0 application crashes randomly

查看:94
本文介绍了C#.NET 4.0应用程序随机崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

移至.net 4.0之后,我们的应用程序出现了奇怪的崩溃.

深入研究之后,我们可以得到低于堆栈跟踪的信息:

 
可能引起问题的功能是:

尝试{

     MyNativeWindow   CreateParams   cp   =              .  //检查句柄是否为空  if    (   m_hWnd   ==     { 
                      MessageBox    }  
                 while ( true)
                {
                    //
                    //if i'm getting true that means i've got WM_QUIT.
                    //
                    bool bReply = LocalModalMessageLoop(null);
                    if (bReply == true)
                       return;
                }
            }
            

Though we are not sure if this is the exact function as the application has huge code and we also have unmanaged code. So from where the exception is thrown is not very clear.

Any kind of help is welcome!

预先感谢!

解决方案

Have you tried to catch the unhandled exception using either Application.UnhandledException or AppDomain.UnhandledException events? These events are raised whenever there is an unhandled exception (like your crash). You can subscribe to those events and check the event arguments for information like Callstack.

我希望这会有所帮助.


Hi,

 We're having strange crashes in the our application after moving to .net 4.0.

My C# application disappears randomly without any exception.The old version was running with .net 3.5 without any crashes, but now that we moved to the .net 4.0 it started crashing randomly.

after digging down we could get below the stacktrace:

at RealNative.RealNativeWindowCopy.DispatchMessageW(MSG& msg)
   at RealNative.RealNativeWindowCopy.LocalModalMessageLoop(Form form)
   at RealNative.RealNativeWindowCopy.CreateWndAndMsgLoopThreadFunction()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

The possible function which is causing issue is like :

try {

               MyNativeWindow nw;
                nw = new MyNativeWindow();
                CreateParams cp = new CreateParams();
                cp.Caption = this.m_winTitle;
                cp.ClassName = "!!" + this.m_classname; // i've modified the treatment so if the classname starts with !!, it will be registered undet that name
                nw.UserWndProc = new UserWndProc(UserWndProcWrapper);

                nw.CreateHandle(cp);
                m_hWnd = nw.Handle; // very important !
                //  check if handle is null
                if (m_hWnd == IntPtr.Zero)
                {
                    MessageBox.Show("Exception", "Error", MessageBoxButtons.OKCancel);
                }
                while (true)
                {
                    //
                    // if i'm getting true that means i've got WM_QUIT.
                    //
                    bool bReply = LocalModalMessageLoop(null);
                    if (bReply == true)
                       return;
                }
            }
          

Though we are not sure if this is the exact function as the application has huge code and we also have unmanaged code. So from where the exception is thrown is not very clear.

Any kind of help is welcome!

Thanks in advance!

解决方案

Have you tried to catch the unhandled exception using either Application.UnhandledException or AppDomain.UnhandledException events? These events are raised whenever there is an unhandled exception (like your crash). You can subscribe to those events and check the event arguments for information like Callstack.

I hope this helps.


这篇关于C#.NET 4.0应用程序随机崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆