当前位置: 代码迷 >> C# >> winform 程序意外异常
  详细解决方案

winform 程序意外异常

热度:110   发布时间:2016-05-05 03:53:05.0
winform 程序意外错误,求救
我已经捕捉了错误, 但是还是找不到错误在哪里


 /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.ControlAppDomain)]
        static void Main(String[] args)
        {
            Application.ThreadException += new ThreadExceptionEventHandler(Form1_UIThreadException);
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            //Get   the   running   instance.   
            Process instance = RunningInstance();
            if (instance == null)
            {
                System.Windows.Forms.Application.EnableVisualStyles();   //这两行实现   XP   可视风格   
                System.Windows.Forms.Application.DoEvents();
                //There   isn't   another   instance,   show   our   form.   

                if (args.Length == 0)
                    Application.Run(new SeverFrom());
                else
                    Application.Run(new SeverFrom(args));


            }
            else
            {
                //There   is   another   instance   of   this   process.   
                HandleRunningInstance(instance);
            }
        }

        private static void Form1_UIThreadException(object sender, ThreadExceptionEventArgs t)
        {
            DialogResult result = DialogResult.Cancel;
            try
            {
                result = ShowThreadExceptionDialog("Windows Forms Error", t.Exception);
            }
            catch
            {
                try
                {
                    MessageBox.Show("Fatal Windows Forms Error",
                        "Fatal Windows Forms Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Stop);
                }
                finally
                {
                    Application.Exit();
                }
            }

            if (result == DialogResult.Abort)
                Application.Exit();
        }



        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            try
            {
                Exception ex = (Exception)e.ExceptionObject;
                string errorMsg = "An application error occurred. Please contact the adminstrator " +
                    "with the following information:/n/n";

                if (!EventLog.SourceExists("ThreadException"))
                {
                    EventLog.CreateEventSource("ThreadException", "Application");
                }

                EventLog myLog = new EventLog();
                myLog.Source = "ThreadException";
                myLog.WriteEntry(errorMsg + ex.Message + "/n/nStack Trace:/n" + ex.StackTrace);
            }
            catch (Exception exc)
            {
                try
                {
                    MessageBox.Show("Fatal Non-UI Error",
                        "Fatal Non-UI Error. Could not write the error to the event log. Reason: "
                        + exc.Message, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }
                finally
                {
                    Application.Exit();
                }
            }
        }






描述:
  Stopped working

问题签名:
  问题事件名称: CLR20r3
  问题签名 01: managerserver.exe
  问题签名 02: 1.0.0.1
  问题签名 03: 50ae2451
  问题签名 04: System
  问题签名 05: 2.0.0.0
  问题签名 06: 4ef6caea
  问题签名 07: 2928
  问题签名 08: 123
  问题签名 09: System.IO.IOException
  OS 版本: 6.1.7601.2.1.0.274.10
  区域设置 ID: 2052

联机阅读隐私声明:
  http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0804

如果无法获取联机隐私声明,请脱机阅读我们的隐私声明:
  C:\Windows\system32\zh-CN\erofflps.txt


------解决思路----------------------
在你所有的异常处打断点,看看出错时是哪句话,具体错误信息等
------解决思路----------------------
主的这段代码,可以说就是一个大口袋,当程序中某个地方发生的异常没有被捕获时,最后就被收到这个口袋里来了。

么我建议,先把这个口袋放在一边,然后在Debug版本下慢慢调试,以发现问题所在。
  相关解决方案