111,120
社区成员
发帖
与我相关
我的任务
分享private void timer_Tick(object sender, EventArgs e)
{
bool isHave = false;
Process[] myProcesses = System.Diagnostics.Process.GetProcesses();//查看所有进程并放到数组myProcesses里
foreach (Process myProcess in myProcesses)//从进程里一个一个读出并在下面的if语句里与“”里的内容比对
{
if ("ProcessMonitoring" == myProcess.ProcessName)
{
isHave = true;//如果为true则退出
break;
}
}
if (!isHave)//如果不存在,则进行相应的操作
{
if (panduan == 1)
{
string wj = "";
timer.Enabled = false;
openFileDialog.Title = "请选择要监控的对像";
if (this.openFileDialog.ShowDialog() == DialogResult.OK)
{
wj = this.openFileDialog.FileName;
if (wj != "")
{
wj = wj.Replace(".exe", "");
}
Process proc = Process.Start(wj);
System.IO.StreamWriter objFile = new System.IO.StreamWriter(Application.StartupPath + "\\监控进程地址.txt");
objFile.WriteLine(wj);
objFile.Close();
objFile.Dispose();
}
else
wj = "";
panduan = 2;
timer.Enabled = true;
}
else
{
string wj = "";
System.IO.StreamReader objFile1 = new System.IO.StreamReader(Application.StartupPath + "\\监控进程地址.txt");
wj = objFile1.ReadLine();
if (wj != "")
{
wj = wj.Replace(".exe", "");
}
Process proc = Process.Start(wj);
objFile1.Close();
objFile1.Dispose();
}
}
}