最近在玩传奇,就用公司的电脑,弄了个安卓模拟器挂机打装备,算是情怀吧。但是公司用的电信宽带,老是断。害的我在家里总是连不上teamview。所以就萌生了如果断网就把进程杀了,利用电信宽带设置中的自动重连给连接上。清明节试了三天,没有啥问题。工具在csdn我的下载中已经有了。这里贴一下代码,做得粗糙,毕竟是第一次做。算是交流吧。
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
namespace RestartNet
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
private Ping ping;
private PingReply res;
private System.Timers.Timer t;
private int delay = 10;
private string processPath = @"C:\Program Files (x86)\Chinatelecom C+W\C+WClient.exe";
private string processName = @"C+WClient";
private bool isStart = false;
public MainWindow()
{
InitializeComponent();
ping = new Ping();
t = new System.Timers.Timer(delay * 1000);//实例化Timer类,设置间隔时间为10000毫秒;
t.Elapsed += new System.Timers.ElapsedEventHandler(theout);//到达时间的时候执行事件;
t.AutoReset = true;//设置是执行一次(false)还是一直执行(true);
timeTextBox.Text = delay.ToString();
processTextBox.Text