需要实现的是: 建立一个windows服务进程,该服务进程同时监测多个进程,当有一个进程中止或不响应时,杀掉这多个进程,并且服务自动停止。本人在线等待各位高手给我解决的方法,并能给出代码,谢谢了~
下面是本人的解决方法,但一直做不下去,因为instance.Responding只能对有窗口显示的进程进行监测,而服务启动的进程是看不到窗口的,。下面给大家看看:(这段代码我尝试着写在了Main函数中,不知道应该写在哪,请指教)
System.ServiceProcess.ServiceController
tmpSC=new System.ServiceProcess.ServiceController();
if(System.Diagnostics.Process.GetProcessesByName("ceshi.exe").Length!=0)
{
// Test to see if the process is responding.
Process[] testprocess;
testprocess= System.Diagnostics.Process.GetProcessesByName("ceshi.exe");
foreach (System.Diagnostics.Process instance in testprocess)
{
if (instance.Responding==true)
{
tmpSC.Pause();
} }
}
else
{
tmpSC.Refresh();
} }
下面是本人的解决方法,但一直做不下去,因为instance.Responding只能对有窗口显示的进程进行监测,而服务启动的进程是看不到窗口的,。下面给大家看看:(这段代码我尝试着写在了Main函数中,不知道应该写在哪,请指教)
System.ServiceProcess.ServiceController
tmpSC=new System.ServiceProcess.ServiceController();
if(System.Diagnostics.Process.GetProcessesByName("ceshi.exe").Length!=0)
{
// Test to see if the process is responding.
Process[] testprocess;
testprocess= System.Diagnostics.Process.GetProcessesByName("ceshi.exe");
foreach (System.Diagnostics.Process instance in testprocess)
{
if (instance.Responding==true)
{
tmpSC.Pause();
} }
}
else
{
tmpSC.Refresh();
} }
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货