static class Program
{
[System.Runtime.InteropServices.DllImport("coredll.Dll", SetLastError = true)]
private static extern int ReleaseMutex(IntPtr hMutex); [System.Runtime.InteropServices.DllImport("coredll.Dll", SetLastError = true)]
private static extern IntPtr CreateMutex(string lpMutexAttributes, bool bInitialOwner, string lpName);
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[MTAThread]
static void Main()
{
try
{
IntPtr hMutex = CreateMutex(null, false, "XXXXX");
if (System.Runtime.InteropServices.Marshal.GetLastWin32Error() != )
{
Application.Run(new FrmMain());
}
else
{
MessageBox.Show("程序已经运行.", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
ReleaseMutex(hMutex);
}
}
catch (Exception)
{ MessageBox.Show("发生未知错误,程序退出!");
Application.Exit();
} }
}

windows mobile 只能运行一个程序实例的更多相关文章

  1. 如何让Windows程序只运行一个程序实例?

    要实现VC++或者MFC只运行一个程序实例,一般采用互斥量来实现,即首先用互斥量封装一个只运行一个程序实例的函数接口: HANDLE hMutex = NULL; void MainDlg::RunS ...

  2. 同一个PC只能运行一个应用实例(考虑多个用户会话情况)

    原文:同一个PC只能运行一个应用实例(考虑多个用户会话情况) class Program { private static Mutex m; [STAThread] static void Main( ...

  3. Winform程序只允许运行一个程序实例

    /// <summary> /// 应用程序的主入口点. /// </summary> [STAThread] static void Main() { Application ...

  4. VC只运行一个程序实例

    方法有很多,以下只是提供一种用的多的 一. 单文档程序 在程序App类的InitInstance中添加如下代码 BOOL CDDZApp::InitInstance() { /*只运行一个实例*/ / ...

  5. C# 只允许运行一个程序实例

    using System; using System.Windows.Forms; using System.Runtime.InteropServices;//使用DllImport的必须. usi ...

  6. 进程的互斥运行:CreateMutex函数实现只运行一个程序实例

    HANDLE hMutex=CreateMutex(NULL,TRUE,"HDZBUkeyDoctorTool"); if(hMutex) { if(ERROR_ALREADY_E ...

  7. 只能运行一个程序,禁止运行多个相同的程序 C#

    原文发布时间为:2009-04-06 -- 来源于本人的百度文章 [由搬家工具导入] Program.cs 里面改成如下: static void Main()        {            ...

  8. wpf程序,只允许运行一个程序实例问题

    https://bbs.csdn.net/topics/390486402 https://codereview.stackexchange.com/questions/20871/single-in ...

  9. Oracle 远程访问配置 在 Windows Forms 和 WPF 应用中使用 FontAwesome 图标 C#反序列化XML异常:在 XML文档(0, 0)中有一个错误“缺少根元素” C#[Win32&WinCE&WM]应用程序只能运行一个实例:MutexHelper Decimal类型截取保留N位小数向上取, Decimal类型截取保留N位小数并且不进行四舍五入操作

    Oracle 远程访问配置   服务端配置 如果不想自己写,可以通过 Net Manager 来配置. 以下配置文件中的 localhost 改为 ip 地址,否则,远程不能访问. 1.网络监听配置 ...

随机推荐

  1. Windows C盘文件夹介绍及说明

    Documents and Settings是什么文件? 答案: 是系统用户设置文件夹,包括各个用户的文档.收藏夹.上网浏览信息.配置文件等. 补:这里面的东西不要随便删除,这保存着所有用户的文档和账 ...

  2. 09_java之面向对象概述

    01面向对象和面向过程的思想 * A: 面向过程与面向对象都是我们编程中,编写程序的一种思维方式 * a: 面向过程的程序设计方式,是遇到一件事时,思考“我该怎么做”,然后一步步实现的过程. * b: ...

  3. npm上传包

    npm上传包 向npm上传一个包是很容易的,只需要三步: 1.在npm官网注册一个账户,然后在cmd中登录账户 注:npm不要使用代理,直接连接 https://registry.npms.org/. ...

  4. BDE View not exists

     Table does not exist. [Microsoft][ODBC SQL Server Driver][SQL Server]对象名 'vw1' 无效. 

  5. GitHub个人使用入门

    今天突然想起来了github 于是开始了入门之旅 如果你用过svn 那么你用起来感觉入门比较快的(至少我是这么感觉的)和在svn服务器上建项目的流程很像 每次修改代码之后提交的过程是: add, co ...

  6. SQL 语句中的in、find_in_set、like的区别

    1.in查询相当于多个or条件的叠加,例如: select * from user where user_id in (1,2,3);等效于select * from user where user_ ...

  7. SpringMVC 配置多个dispatcher 及WebApplicationInitializer的使用

    SpringMVC 在配置多个dispatcher时,一般可以如下配置: <!-- spring mvc start --> <servlet> <servlet-nam ...

  8. 在 Golang 中使用 Protobuf

    wget https://github.com/google/protobuf/releases/download/v2.6.1/protobuf-2.6.1.tar.gztar zxvf proto ...

  9. Codeforces 712D DP

    题意:有2个人玩游戏,他们都有个初始值a和b, 游戏进行t轮, 每次可以选择加上一个[-k, +k]之间的数字,问有多少种方案a的和严格大于b的和. 思路:如果不考虑多于这个条件,只是询问有多少种方案 ...

  10. ios野指针的3种常见情况