电信宽带自动重连代码(目的是teamview在家连电脑的时候总是因为电信宽带自动断网而连不上)

为了解决使用Teamview远程连接公司电脑时因电信宽带断网导致的连接问题,作者编写了一个自动重连代码。当网络断开时,该代码会终止相关进程,并利用电信宽带的自动重连功能恢复网络。在清明节期间经过测试,运行稳定。虽然代码较为初级,作者欢迎读者提供反馈和建议,因为这是他首次尝试编写exe程序,主要背景是游戏开发。
摘要由CSDN通过智能技术生成

最近在玩传奇,就用公司的电脑,弄了个安卓模拟器挂机打装备,算是情怀吧。但是公司用的电信宽带,老是断。害的我在家里总是连不上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 
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值