日期:2014-05-20  浏览次数:21366 次

C# WinForm窗体没有关闭自动运行Dispose()的问题
如题,应用程序跑了几分钟到十几分钟不等,一点概率出现主窗体被Dispse()掉了,程序没有显示调用关闭之类的代码,也没有关闭窗体,突然到Application.Run(new Form())这里抛出异常:

C# code

   static class Program
    {
        private const int WS_SHOWNORMAL = 1;
        private const int SW_RESTORE = 9;
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
      
            //获取正在运行的进程
            Process instance = RunningInstance();
            if (instance == null)
            {

                DevExpress.UserSkins.BonusSkins.Register();
                DevExpress.UserSkins.OfficeSkins.Register();
                DevExpress.Skins.SkinManager.EnableFormSkins();
                DevExpress.Skins.SkinManager.EnableMdiFormSkins();
               // DevExpress.LookAndFeel.UserLookAndFeel.Default.SkinName = "Blue";
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                Application.Run(MainForm.Instance);
            }
            else
            {
                HandleRunningInstance(instance);
            }
        }




异常不是每次都有的,异常信息为AccessViolationException 尝试读取或写入受保护的内存。这通常指示其他内存已损坏。


------解决方案--------------------
学习。。。
------解决方案--------------------
C# code

DevExpress.UserSkins.BonusSkins.Register();
                DevExpress.UserSkins.OfficeSkins.Register();
                DevExpress.Skins.SkinManager.EnableFormSkins();
                DevExpress.Skins.SkinManager.EnableMdiFormSkins();

------解决方案--------------------
devexpress官方的解释:
A similar problem was fixed in the AccessViolationException occurs when using 24x24 Icons for toolbar images bug report. However, from the report's Version field, I see that you are already using the latest version