zoukankan      html  css  js  c++  java
  • c#,Winform同一系统中只运行一个实例。

    代码
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Windows.Forms;

    namespace TestSingleProcessInSameOS
    {
        
    static class Program
        {
            
    /// <summary>
            
    /// 应用程序的主入口点。
            
    /// </summary>
            [STAThread]
            
    static void Main()
           {
               
    bool ret;
               System.Threading.Mutex mutex 
    = new System.Threading.Mutex(true, Application.ProductName, out ret);
               
    if (ret)
               {
                   System.Windows.Forms.Application.EnableVisualStyles();
                   System.Windows.Forms.Application.DoEvents();
                   System.Windows.Forms.Application.Run(
    new Form1());   
                   mutex.ReleaseMutex();
               }
               
    else
               {
                   MessageBox.Show(
    null"有一个和本程序相同的应用程序已经在运行,请不要同时运行多个本程序。\n\n这个程序即将退出。", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                   Application.Exit();
    //退出程序   
               }



            }
        }
    }

    ////////////////////////////////
    ////////Sixi. Let it be.../////
    //////////////////////////////

  • 相关阅读:
    【机器学习】关于判别模型和生成模型
    Delphi新手跟我学写CALL,附完整原程序
    QT事件研究的文章
    杂烩:QWidget、QGraphics、QtQuick
    Golang全接触
    学会使用git
    代码创建 WPF 旋转动画
    值得推荐的C/C++框架和库 very good
    可恶的QT隐式共享
    Notes on OpenSSL and Qt(ssl.pri,qsslocket_openssl_symbols.cpp)
  • 原文地址:https://www.cnblogs.com/sixiweb/p/1766302.html
Copyright © 2011-2022 走看看