日期:2014-05-17  浏览次数:21083 次

C# MainForm程序运行时一闪而过
C# MainForm程序在开发环境下运行正常,编译后在某些电脑上运行正常,但在有些电脑上运行时一闪而过就退出了,不知道是怎么回事!
应用程序入口代码如下:
  static void Main()
        {
            bool createNew;
            appMutex = new System.Threading.Mutex(true, "ht", out createNew);
            if (!createNew)
            {
                try
                {
                    appMutex.Close(); appMutex = null;
                    MessageBox.Show("当前程序已经运行!", "后台管理");
                }
                catch { }
                return;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MainForm());
        }
MainForm的Load事件代码如下:
 private void MainForm_Load(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            timer1.Interval = Settings.Instance.ServerTimeSpan;
            if (Settings.Instance.ServerStat)
            {
                timer1.Start();
            }
            notifyIcon1.Visible = true;
            this.WindowState = FormWindowState.Minimized;
            this.Visible = false;
            this.ShowInTaskbar = false;
            notifyIcon1.ShowBalloonTip(1, "提示", "后台管理运行中.....", ToolTipIcon.Info);
            System.Threading.Thread.Sleep(2000);
            notifyIcon1.Visible = false;
            notifyIcon1.Visible = true;
        }