CnMichael

博客园 首页 新随笔 联系 订阅 管理

今天在用别人软件的时候突然发现, 软件第二次打开的时候给出提示信息: "程序已经启动", 突然想到我们现在正在做的项目,马上就开始思考如何实现,

我们都知道一般程序启动都会在进程里面启用一个新进程, 当然个别程序例外, 应该只是一个隐藏, 有待考证, 网上搜了下, 嘿嘿, 知之为知之, 不知

Google知嘛, 时下Google绯闻太多了, 嘿嘿, 这里就不讨论了, 说了这么多废话, 代码如下:

转载CSDN维也纳, 修改后测试可用:

以C# winform程序为例, 在Program.cs中加入如下代码;

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Threading;

namespace EagleSoft.App_EagleSoft_All
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            
            //判断软件是否已经启动
            bool temp;
            Mutex mutex = new Mutex(true, Application.ProductName, out   temp);
            if (temp)
            {
                Application.Run(new EagleSoft_LoginProcess());
                mutex.ReleaseMutex();
            }
            else
            {
                MessageBox.Show("温馨提示: 程序已经启动!","xxxxxx",MessageBoxButtons.OK,MessageBoxIcon.Information);
            }
        }
    }
}

 

嘿嘿,每天前进一小步, 人生前进一大步, 以这句话来勉励自己, 很多天没上博客了, 感觉失落了许多, 不过工作还是挺忙的任务也挺重,

自己又刚毕业, 加生病, 诸多烦恼, 哎... 琐碎之事.

posted on 2010-06-10 15:55  CnMichael  阅读(582)  评论(0编辑  收藏  举报