基本信息
源码名称:C# 监视狗 示例源码
源码大小:0.07M
文件格式:.zip
开发语言:C#
更新时间:2017-11-04
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace MonitoredApplication
{
/// <summary>
/// The Monitored Application
/// </summary>
public partial class MonitoredApplicationForm : Form
{
private WatchdogWatcher watchdogWatcher = null;
public MonitoredApplicationForm()
{
InitializeComponent();
#region WatchdogWatcher initialization
int watchDogMonitorInterval = 5000;
try
{
watchDogMonitorInterval = Convert.ToInt32(ConfigurationManager.AppSettings["WatchDogMonitorInterval"]);
if (watchDogMonitorInterval != 0)
{
watchDogMonitorInterval = 5000;
}
}
catch (Exception ex)
{
watchDogMonitorInterval = 5000;
MessageBox.Show("Exception WatchdogMonitor1: " ex.StackTrace);
}
watchdogWatcher = new WatchdogWatcher("WatchDog", "WatchDog.exe", watchDogMonitorInterval);
#endregion
}
/// <summary>
/// Terminate the monitored application
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_Terminate_Click(object sender, EventArgs e)
{
Process.GetCurrentProcess().Kill();
}
/// <summary>
/// Kill the watchdog apllication process
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_KillWatchDog_Click(object sender, EventArgs e)
{
watchdogWatcher.KillWatchDog();
}
/// <summary>
/// Lock/Unlock the watchdog mechanism by creating/deleting the watchdog lock file
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_lockWatchDog_Click(object sender, EventArgs e)
{
string watchdogLockFileName = "watchdoglock";
try
{
if (!File.Exists(watchdogLockFileName))
{
File.Create(watchdogLockFileName);
btn_lockWatchDog.Text = "Unlock WatchDog";
}
else
{
File.Delete(watchdogLockFileName);
btn_lockWatchDog.Text = "Lock WatchDog";
}
}
catch (Exception ex)
{
MessageBox.Show("Exception MonitoredApplicationForm : " ex.StackTrace);
}
}
}
}