| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Winsoft.GOV.WCF;
- namespace Winsoft.GOV.ConsoleHost
- {
- class Program
- {
- static void Main(string[] args)
- {
- try
- {
- if (!IsExistProcess())
- {
- Host.Start();
- }
- else
- {
- System.Console.WriteLine(String.Format("'{0}'程序已经存在.", Process.GetCurrentProcess().ProcessName));
- }
- }
- finally
- {
- System.Console.ReadLine();
- }
- }
- /// <summary>
- /// Is exist same process
- /// </summary>
- /// <returns></returns>
- public static void KillExistProcess()
- {
- var current = Process.GetCurrentProcess();
- var pArrayy = System.Diagnostics.Process.GetProcessesByName(current.ProcessName);
- if (pArrayy == null || pArrayy.Length == 0)
- {
- return;
- }
- foreach (var item in pArrayy)
- {
- if (!item.ProcessName.ToUpper().Contains(current.ProcessName.ToUpper()))
- {
- continue;
- }
- if (item.Id != current.Id && item.MainModule.ModuleName.ToUpper() == current.MainModule.ModuleName.ToUpper())
- {
- item.Kill();
- }
- }
- }
- public static Boolean IsExistProcess()
- {
- var current = Process.GetCurrentProcess();
- var pArrayy = System.Diagnostics.Process.GetProcessesByName(current.ProcessName);
- if (pArrayy == null || pArrayy.Length == 0)
- {
- return false;
- }
- foreach (var item in pArrayy)
- {
- if (!item.ProcessName.ToUpper().Contains(current.ProcessName.ToUpper()))
- {
- continue;
- }
- if (item.Id != current.Id && item.MainModule.ModuleName.ToUpper() == current.MainModule.ModuleName.ToUpper())
- {
- return true;
- }
- }
- return false;
- }
- }
- }
|