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();
}
}
///
/// Is exist same process
///
///
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;
}
}
}