zoukankan      html  css  js  c++  java
  • 【源码】Fast2011 启动主进程只有一个

    using System;
    using System.Collections.Generic;
    using System.Windows.Forms;
    using System.Diagnostics;//引入Process 类
    using System.Reflection;//引入Assembly
    using System.Runtime.InteropServices; //需要获取句柄,激活前一实例
    using System.Threading;//需要用到mutex

    namespace fasta2011
    {
    static class Program
    {
    /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    private const int WS_SHOWNORMAL = 1;
    [DllImport("User32.dll")]
    private static extern bool ShowWindowAsync(IntPtr hWnd, int cmdShow);
    [DllImport("User32.dll")]
    private static extern bool SetForegroundWindow(IntPtr hWnd);
    [STAThread]
    static void Main()
    {
    Process instance = GetRunningInstance();
    if (instance == null)
    {
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(new Form1());
    }
    else
    {
    HandleRunningInstance(instance);
    }
    //Application.EnableVisualStyles();
    //Application.SetCompatibleTextRenderingDefault(false);
    //Application.Run(new Form1());
    }
    public static Process GetRunningInstance()
    {
    Process current = Process.GetCurrentProcess();
    Process[] processes = Process.GetProcessesByName(current.ProcessName);

    foreach (Process process in processes)
    {
    if (process.Id != current.Id)
    if (Assembly.GetExecutingAssembly().Location.Replace("/", "\\") == current.MainModule.FileName)
    return process;
    }
    return null;
    }

    public static void HandleRunningInstance(Process instance)
    {

    ShowWindowAsync(instance.MainWindowHandle, WS_SHOWNORMAL);
    SetForegroundWindow(instance.MainWindowHandle);
    }
    }
    }

  • 相关阅读:
    van Emda Boas
    斐波那契堆
    NTT
    FFT
    KDTree
    扩展kmp
    kmp
    Dancing Links
    树的prufer编码
    有向图最小路径覆盖
  • 原文地址:https://www.cnblogs.com/chusiping/p/2224226.html
Copyright © 2011-2022 走看看