private void btnTestVpn_Click(object sender, EventArgs e) { VPNManager vpnMgr = new VPNManager(this.LogManager); VPNItem vpnItem = this.GetVpnParams(); if (null != vpnItem) { this.OnTestChanged(true); Thread t = new Thread(new ThreadStart(delegate() { LogManager.InfoWithCallback(string.Format("-> 正在开始对VPN: 名称={0},IP={1} 进行网络重连测试,请稍等......", vpnItem.EntryName, vpnItem.IP)); bool isConnected = vpnMgr.Reconnect(vpnItem); if (isConnected) { LogManager.InfoWithCallback(string.Format("-> 对VPN: 名称={0},IP={1} 网络重连成功,网络恢复正常", vpnItem.EntryName, vpnItem.IP)); } else { LogManager.InfoWithCallback(string.Format("-> 对VPN: 名称={0},IP={1} 网络重连失败,请检查IP,用户名或者密码是否正确!", vpnItem.EntryName, vpnItem.IP)); } this.OnTestChanged(false); })); t.Start(); } }
public void Test() { IList <VPNItem> vpnList = this.GetVpnList(); if ((null != vpnList) && (vpnList.Count > 0)) { VPNManager vpnMgr = new VPNManager(this.LogManager); DetectionParamsItem paramsItem = new DetectionParamsItem(); //VPNItem vpnItem = vpnList[0]; paramsItem.ReconnectType = ReconnectType.VPN; paramsItem.VpnList = vpnList; //paramsItem.VpnList.Add(vpnItem); this.OnTestChanged(true); Thread t = new Thread(new ThreadStart(delegate() { //LogManager.InfoWithCallback(string.Format("-> 正在开始对VPN: 名称={0},IP={1} 进行网络重连测试,请稍等......", vpnItem.EntryName, vpnItem.IP)); bool isConnected = vpnMgr.Reconnect(paramsItem); //if (isConnected) //{ // LogManager.InfoWithCallback(string.Format("-> 对VPN: 名称={0},IP={1} 网络重连成功,网络恢复正常", vpnItem.EntryName, vpnItem.IP)); //} //else //{ // LogManager.InfoWithCallback(string.Format("-> 对VPN: 名称={0},IP={1} 网络重连失败,请检查IP,用户名或者密码是否正确!", vpnItem.EntryName, vpnItem.IP)); //} this.OnTestChanged(false); })); t.Start(); } }