资源简介
csharp-Windows服务及进程监控程序,可以设定要监控的进程和服务名称,监控到没运行自动启动.服务监控,进程监控
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using log4net;
namespace HQ.ServiceWatch
{
public class ProcessWatcher
{
static readonly ILog _log = LogManager.GetLogger(“TraceLogFileAppender“);
//字段
public string[] _processAddress;
public int WaitSeconds;
///
/// 开始监控
///
public void StartWatch()
{
if (this._processAddress != null)
{
if (this._processAddress.Length > 0)
{
foreach (string str in _processAddress)
{
if (str.Trim() != ““)
{
if (File.Exists(str.Trim()))
{
this.ScanProcessList(str.Trim());
}
}
}
}
}
}
///
/// 扫描进程列表,判断进程对应的全路径是否与指定路径一致
/// 如果一致,说明进程已启动
/// 如果不一致,说明进程尚未启动
///
///
private void ScanProcessList(string address)
{
Process[] arrayProcess = Process.GetProcesses();
foreach (Process p in arrayProcess)
{
//System、Idle进程会拒绝访问其全路径
if (p.ProcessName != “System“ && p.ProcessName != “Idle“)
{
try
{
if (this.FormatPath(address) == this.FormatPath(p.MainModule.FileName.ToString()))
{
//进程已启动
this.WatchProcess(p address WaitSeconds);
return;
}
}
catch
{
//拒绝访问进程的全路径
//_log.Info(“进程(“ + p.Id.ToString() + “)(“ + p.ProcessName.ToString() + “)拒绝访问全路径!“);
}
}
}
//进程尚未启动
Process process = new Process();
process.StartInfo.FileName = address;
process.Start();
this.WatchProcess(process address WaitSeconds);
}
///
/// 监听进程
///
///
///
private void WatchProcess(Process process string address int waitSeconds)
{
ProcessRestart objProcessRestart = new ProcessRestart(process address waitSeconds);
Thread thread = new Thread(new ThreadStart(objProcessRestart.RestartProcess));
thread.Start();
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 605 2015-04-02 17:56 HQ.ServiceWatch\HQ.ServiceWatch\App.config
文件 13312 2015-04-02 17:54 HQ.ServiceWatch\HQ.ServiceWatch\bin\Debug\HQ.ServiceWatch.exe
文件 605 2015-04-02 17:49 HQ.ServiceWatch\HQ.ServiceWatch\bin\Debug\HQ.ServiceWatch.exe.config
文件 32256 2015-04-02 17:54 HQ.ServiceWatch\HQ.ServiceWatch\bin\Debug\HQ.ServiceWatch.pdb
文件 24224 2015-04-02 17:55 HQ.ServiceWatch\HQ.ServiceWatch\bin\Debug\HQ.ServiceWatch.vshost.exe
文件 605 2015-04-02 17:49 HQ.ServiceWatch\HQ.ServiceWatch\bin\Debug\HQ.ServiceWatch.vshost.exe.config
文件 0 2015-04-02 15:26 HQ.ServiceWatch\HQ.ServiceWatch\bin\Debug\log\error.txt
文件 2281 2015-03-13 16:26 HQ.ServiceWatch\HQ.ServiceWatch\bin\Debug\log4net.config
文件 301056 2015-04-02 14:32 HQ.ServiceWatch\HQ.ServiceWatch\bin\Debug\log4net.dll
文件 1517265 2015-04-02 14:32 HQ.ServiceWatch\HQ.ServiceWatch\bin\Debug\log4net.xm
文件 1321 2015-04-02 17:52 HQ.ServiceWatch\HQ.ServiceWatch\bin\Debug\Logs\20150402.log
文件 279040 2015-04-02 14:33 HQ.ServiceWatch\HQ.ServiceWatch\bin\Debug\Topshelf.dll
文件 12800 2015-04-02 17:55 HQ.ServiceWatch\HQ.ServiceWatch\bin\Release\HQ.ServiceWatch.exe
文件 605 2015-04-02 17:49 HQ.ServiceWatch\HQ.ServiceWatch\bin\Release\HQ.ServiceWatch.exe.config
文件 26112 2015-04-02 17:55 HQ.ServiceWatch\HQ.ServiceWatch\bin\Release\HQ.ServiceWatch.pdb
文件 24224 2015-04-02 17:55 HQ.ServiceWatch\HQ.ServiceWatch\bin\Release\HQ.ServiceWatch.vshost.exe
文件 605 2015-04-02 17:49 HQ.ServiceWatch\HQ.ServiceWatch\bin\Release\HQ.ServiceWatch.vshost.exe.config
文件 490 2010-03-17 22:39 HQ.ServiceWatch\HQ.ServiceWatch\bin\Release\HQ.ServiceWatch.vshost.exe.manifest
文件 301056 2015-04-02 14:32 HQ.ServiceWatch\HQ.ServiceWatch\bin\Release\log4net.dll
文件 1517265 2015-04-02 14:32 HQ.ServiceWatch\HQ.ServiceWatch\bin\Release\log4net.xm
文件 279040 2015-04-02 14:33 HQ.ServiceWatch\HQ.ServiceWatch\bin\Release\Topshelf.dll
文件 3159 2015-04-02 17:56 HQ.ServiceWatch\HQ.ServiceWatch\HQ.ServiceWatch.csproj
文件 2281 2015-04-02 17:56 HQ.ServiceWatch\HQ.ServiceWatch\log4net.config
文件 7249 2015-04-02 14:52 HQ.ServiceWatch\HQ.ServiceWatch\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
文件 854 2015-04-02 17:55 HQ.ServiceWatch\HQ.ServiceWatch\obj\Debug\HQ.ServiceWatch.csproj.FileListAbsolute.txt
文件 14319 2015-04-02 15:07 HQ.ServiceWatch\HQ.ServiceWatch\obj\Debug\HQ.ServiceWatch.csprojResolveAssemblyReference.cache
文件 13312 2015-04-02 17:54 HQ.ServiceWatch\HQ.ServiceWatch\obj\Debug\HQ.ServiceWatch.exe
文件 32256 2015-04-02 17:54 HQ.ServiceWatch\HQ.ServiceWatch\obj\Debug\HQ.ServiceWatch.pdb
文件 0 2015-04-02 14:14 HQ.ServiceWatch\HQ.ServiceWatch\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
文件 0 2015-04-02 14:14 HQ.ServiceWatch\HQ.ServiceWatch\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
............此处省略65个文件信息
- 上一篇:特征的选择与提取 模式识别
- 下一篇:房屋租赁管理系统源码
评论
共有 条评论