zoukankan      html  css  js  c++  java
  • [转]CS DevExpress程序启动(主窗体初始化优化)

    (转载请删除括号里的内容)

      在进入程序主界面时,某些情况下主界面的初始化会消耗很长时间,例如一些复杂的业务系统,可能会从服务器上下载最新的数据进行展示等等,在这种情况下,我们可以采用一个进度界面展示“系统正在加载...”,等主界面加载完之后,进度界面退出,主界面展示出来。

      在Program.cs中进行操作:

      实例包含三个窗体:主窗体(FrmMain)、登陆窗体(FrmLogin)、进度窗体(SplashScreen1)

    using System;
    using System.Windows.Forms;
    using DevExpress.LookAndFeel;
    using System.Threading;
    using System.Reflection;
    using System.Configuration;
    
    namespace MainUSL
    {
        static class Program
        {
            private static ApplicationContext context;
            private static  FrmMain mForm;
            private static Thread oThread;
            private static  SplashScreen1 sForm;  
            /// <summary>
            /// 应用程序的主入口点。
            /// </summary>
            [STAThread]
            static void Main()
            {
                //DefaultLookAndFeel defaultLookAndFeel1 = new DefaultLookAndFeel();
                //defaultLookAndFeel1.LookAndFeel.SetSkinStyle("Office 2010 Blue");
                //string skinName = ConfigurationManager.AppSettings["ThemeSkin"].ToString();
                //UserLookAndFeel.Default.SkinName = skinName;
                UserLookAndFeel.Default.SkinName = "DevExpress Dark Style";
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-CN");
                bool bMutexCreated = true;
                using (new Mutex(true, Assembly.GetExecutingAssembly().FullName, out bMutexCreated))
                {
                    if (!bMutexCreated)
                    {
                        DevExpress.XtraEditors.XtraMessageBox.Show("已经存在一个实例在运行!");
                        return;
                    }
                    FrmLogin frmLogin = new FrmLogin();
                    if (frmLogin.ShowDialog() == DialogResult.OK)
                    {
                        DoStartup();
                    }
                }
                //Application.Run(new FrmLogin());
                //Application.Run(new FrmMain());
            }
            static void DoStartup()
            {
                try
                {
    
                    sForm = new SplashScreen1();
                    //新建一个线程
                    oThread = new Thread(new ThreadStart(ShowFlash));
                    //设置线程级别
                    oThread.Priority = ThreadPriority.Lowest;
                    //后台线程
                    oThread.IsBackground = true;
                    //启动flash
                    oThread.Start();
                    //事件订阅(在线程结束时调用OnAppIdle方法)
                    Application.Idle += new EventHandler(OnAppIdle);
                    mForm = new FrmMain();
                    //Application.Run(mForm);
                    context = new ApplicationContext();
                    Application.Run(context);
                }
                catch (Exception e)
                {
                    CommonOperator.ExceptionClass.RecordException(e.ToString());
                    Application.Exit();
                }
            }
            /// <summary>
            /// 线程结束后事件
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private static void OnAppIdle(object sender, EventArgs e)
            {
                try
                {
                    if (context.MainForm == null)
                    {
                        //取消事件订阅
                        Application.Idle -= new EventHandler(OnAppIdle);
                        //标识状态
                        //mForm.PreLoad();
                        //为当前线程设置主窗体
                        context.MainForm = mForm;
                        //启动主界面
                        Thread.Sleep(5000);
                        context.MainForm.Show();
                        //终止flash
                        oThread.Abort();
                        GC.Collect();
                        Application.DoEvents();
                    }
                }
               catch (Exception ex)
                {
                    CommonOperator.ExceptionClass.RecordException(ex.ToString());
                }
            }
    
            static void ShowFlash()
            {
                sForm.ShowDialog();
            }
        }
    }

    --------------------
    作者:沙耶
    来源:CNBLOGS
    原文:https://www.cnblogs.com/ShaYeBlog/p/10535863.html

  • 相关阅读:
    UOJ.26.[IOI2014]Game(交互 思路)
    Good Bye 2016 F.New Year and Finding Roots(交互)
    Codeforces.835E.The penguin's game(交互 按位统计 二分)
    Codeforces.744B.Hongcow's Game(交互 按位统计)
    Codeforces.862D.Mahmoud and Ehab and the binary string(交互 二分)
    正睿OI 提高 Day1T3 ZYB玩字符串(DP)
    划分vlan
    2三层交换机实现vlan间的路由
    交换机基础-交换机远程telnet
    自动化运维环境的搭建问题处理
  • 原文地址:https://www.cnblogs.com/kevinl/p/14689601.html
Copyright © 2011-2022 走看看