基本信息
源码名称:程序看门狗源码(进程监控)
源码大小:0.14M
文件格式:.rar
开发语言:C#
更新时间:2019-08-01
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
看门狗,采用C#编写,使用了process 就是监控程序,发生异常的时候可以有及时响应
看门狗,采用C#编写,使用了process 就是监控程序,发生异常的时候可以有及时响应
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Threading;
using System.IO;
namespace WatchDog
{
class Program
{
static AddCv[] appt = new AddCv[10];
static Thread[] thread = new Thread[10];
static int count;
static void Main(string[] args)
{
//加强程序健壮性初始化建立文件夹
//AppDomain.CurrentDomain.ProcessExit = new EventHandler(CurrentDomain_ProcessExit);
Program.CreateLog();
Program.CreateXml();
Program.ReadXml();
Program.CallMonitor();
//return;
}
private static void CurrentDomain_ProcessExit(object sender, EventArgs e)
{
return;
}
private static void CallStop()
{
Monitor active = new Monitor();
active.pactive = false;
for (int i = 0; i < count; i )
{
thread[i].Abort();
FindProcess(appt[i].Proname.Substring(appt[i].Proname.LastIndexOf("\\") 1));
}
}
private static bool FindProcess(string proname)
{
Process[] processes = Process.GetProcesses();
for (int i = 0; i < processes.Length; i )
{
if (string.Compare(processes[i].ProcessName, proname, true) == 0)
{
processes[i].Kill();
}
}
return false;
}
private static void ReadXml()
{
try
{
MyXml a = new MyXml();
int c;
count = int.Parse(a.XmlNodeRead("pronum"));
c = int.Parse(a.XmlNodeRead("prosec"));
for (int i = 0; i < count; i )
{
appt[i] = new AddCv(a.XmlNodeRead("propath_" (i 1)), c);
}
}
catch (Exception e)
{
//记录在错误信息中
if (!Directory.Exists(System.Environment.CurrentDirectory "\\Errlog") && e.Message != null)
{
Directory.CreateDirectory(System.Environment.CurrentDirectory "\\Errlog");
}
string temp = null;
if (File.Exists(System.Environment.CurrentDirectory "\\Errlog\\" DateTime.Now.ToString("yyyy-MM-dd") ".txt"))
{
temp = File.ReadAllText(System.Environment.CurrentDirectory "\\Errlog\\" DateTime.Now.ToString("yyyy-MM-dd") ".txt");
}
temp = "[" DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") "]" e.Message;
File.WriteAllText(System.Environment.CurrentDirectory "\\Errlog\\" DateTime.Now.ToString("yyyy-MM-dd") ".txt", temp "\r\n");
}
}
private static void CreateLog()
{
MyLog a = new MyLog();
a.CreateLogDir("Log");
a.CreateLogDir("ErrLog");
}
private static void CreateXml()
{
MyXml a = new MyXml();
a.CreateXmlconf("conf.xml");
}
private static void CallMonitor()
{
for (int i = 0; i < appt.Length; i )
{
thread[i] = new Thread(new ParameterizedThreadStart(Program.monitor));
thread[i].Start(appt[i]);
}
}
private static void monitor(object data)
{
if (data is AddCv)
{
AddCv ap = (AddCv)data;
Monitor Tname = new Monitor();
Tname.moniotsec=ap.Prosec;
Tname.pronames=ap.Proname;
}
}
}
}