1. static class Program
  2. {
  3. [System.Runtime.InteropServices.DllImport("coredll.Dll", SetLastError = true)]
  4. private static extern int ReleaseMutex(IntPtr hMutex);
  5.  
  6. [System.Runtime.InteropServices.DllImport("coredll.Dll", SetLastError = true)]
  7. private static extern IntPtr CreateMutex(string lpMutexAttributes, bool bInitialOwner, string lpName);
  8. /// <summary>
  9. /// 应用程序的主入口点。
  10. /// </summary>
  11. [MTAThread]
  12. static void Main()
  13. {
  14. try
  15. {
  16. IntPtr hMutex = CreateMutex(null, false, "XXXXX");
  17. if (System.Runtime.InteropServices.Marshal.GetLastWin32Error() != )
  18. {
  19. Application.Run(new FrmMain());
  20. }
  21. else
  22. {
  23. MessageBox.Show("程序已经运行.", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
  24. ReleaseMutex(hMutex);
  25. }
  26. }
  27. catch (Exception)
  28. {
  29.  
  30. MessageBox.Show("发生未知错误,程序退出!");
  31. Application.Exit();
  32. }
  33.  
  34. }
  35. }

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. PHP中使用mkdir创建多级目录的方法

    function mkdirs($dir)    {    if(!is_dir($dir))    {    if(!mkdirs(dirname($dir))){    return false; ...

  2. django No migrations to apply 问题解决

    最近在用django写项目,有的时候字段不够用,需要models增加字段,但是想回滚或者修改或者修改了属性等,例如忘了添加meta table于是操作了migrations 导致makemigrati ...

  3. Python添加模块

    参考博客:http://blog.csdn.net/damotiansheng/article/details/43916881 http://my.oschina.net/leejun2005/bl ...

  4. Yaml学习笔录

    YAML概要 [YAML](http://yaml.org/)是"YAML Ain't a Markup Language"(YAML不是一种置标语言)的递归缩写,早先YAML的意 ...

  5. Tkinter按钮(Button)

    Python - Tkinter Button按钮组件是用来添加一个Python应用程序中的按钮.这些按钮可以显示文字或图像,表达按钮的目的.当你按一下按钮时,您可以附加到一个按钮的函数或方法,该方法 ...

  6. TabControl关闭选项卡

    关闭TabControl选项卡: Private Sub TabControl_Main_CloseButtonClick(sender As Object, e As EventArgs) Hand ...

  7. objective c to pas

    https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplicationDelegate_Protocol ...

  8. C#异步编程的一些认识

    1.使用委托类型的BeginXXX,EndXXX 2.使用事件 3.使用aysnc,await关键字,会自动切换回UI线程,启动方法的线程可以被重用,线程没有阻塞.内部其实是封闭了Task类的Cont ...

  9. <转> win7下破解已安装的VS2008

    http://renfan.blog.51cto.com/3466724/754301 在win7系统下,已安装的VS2008维护界面是不显示序列号输入的,需要按以下步骤进行才能破解 1.点击“卸载/ ...

  10. python pipenv 包管理

    原文链接:https://robots.thoughtbot.com/how-to-manage-your-python-projects-with-pipenv 翻译者:Jiong 在thought ...