• ProcessHelpers


    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Linq;
    using System.Text;
    
    namespace ZB.QueueSys.Common
    {
        public class ProcessHelpers
        {
            //private static ProcessHelper instance;
            //public static ProcessHelper Instance
            //{
            //    get
            //    {
            //        if (instance == null) instance = new ProcessHelper();
            //        return ProcessHelper.instance;
            //    }
            //}
    
            //定义一个用于保存静态变量的实例
            private static ProcessHelpers instance = null;
            //定义一个保证线程同步的标识
            private static readonly object locker = new object();
            //构造函数为私有,使外界不能创建该类的实例
            private ProcessHelpers() { }
            public static ProcessHelpers Instance
            {
                get
                {
                    if (instance == null)
                    {
                        lock (locker)
                        {
                            if (instance == null) instance = new ProcessHelpers();
                        }
                    }
                    return instance;
                }
            }
    
            /// <summary>
            /// 关闭进程
            /// </summary>
            /// <param name="processName">进程名</param>
            public void KillProcessByName(string processName)
            {
                try
                {
                    Process[] myproc = Process.GetProcesses();
                    foreach (Process item in myproc)
                    {
                        if (item.ProcessName == processName)
                        {
                            item.CloseMainWindow();
                            item.Kill();
                        }
                    }
                }
                catch { return; }
            }
    
            /// <summary>
            /// 启动进程
            /// </summary>
            /// <param name="processName">进程名,完全限定名</param>
            public void StartProcessByName(string processName)
            {
                System.Diagnostics.Process.Start(processName);
                //Process process = new Process();//声明一个进程类对象
                //process.StartInfo.FileName = processName;//Application.StartupPath + "\\AutoUpdate.exe";
                //process.Start();
            }
    
            public void StartProcessByName(string processName, string param)
            {
                //System.Diagnostics.Process.Start(processName);
                Process p = new Process();//声明一个进程类对象
                p.StartInfo.FileName = processName;// Application.StartupPath + "\\AutoUpdate.exe";
                p.StartInfo.UseShellExecute = true;
                p.StartInfo.Arguments = param;
                p.Start();
            }
    
    
        }
    }
    

      

  • 相关阅读:
    【JZOJ4807】破解
    输入挂(更新)
    Gorgeous Sequence(线段树)
    线段树套路系列
    hdu 3333 离线线段树 + 思维/树状数组 /在线主席树
    3183 RMQ / 贪心(坑成。。)
    hdu3594 强连通(仙人掌图)
    hdu3639 强连通
    hdu3861 强连通+最小路径覆盖
    图论--最小树形图朱刘算法模板
  • 原文地址:https://www.cnblogs.com/YYkun/p/16836954.html
Copyright © 2020-2023  润新知