コード例 #1
0
        public void Redial()
        {
            _util.TryDisConnectVpn();
            Thread.Sleep(2000);

            bool disConnected = !_util.GetCurrentConnectingVpnNames().Contains(_util.VpnName);

            while (!disConnected)
            {
                try
                {
                    _util.TryConnectVpn();
                    disConnected = !_util.GetCurrentConnectingVpnNames().Contains(_util.VpnName);
                    Thread.Sleep(2000);
                }
                catch
                {
                    // ignored
                }
            }

            //在NAT下使用VPN,断开VPN时会导致原网络断开,需要重启网卡,暂时没有找到更好的解决方法
            if (!string.IsNullOrEmpty(NetInterface))
            {
                NetInterfaceUtils.ChangeNetworkConnectionStatus(false, NetInterface);
                Thread.Sleep(2000);
                NetInterfaceUtils.ChangeNetworkConnectionStatus(true, NetInterface);
                Thread.Sleep(2000);
            }

            _util.TryConnectVpn();
            Thread.Sleep(2000);

            bool connected = _util.GetCurrentConnectingVpnNames().Contains(_util.VpnName);

            while (!connected)
            {
                try
                {
                    _util.TryConnectVpn();
                    connected = _util.GetCurrentConnectingVpnNames().Contains(_util.VpnName);
                    Thread.Sleep(2000);
                }
                catch
                {
                    // ignored
                }
            }
        }
コード例 #2
0
        public void Redial()
        {
            Console.WriteLine("Trying to disconnect Vpn:" + _util.VpnName);
            _util.TryDisConnectVpn();
            Thread.Sleep(1000);
            Console.WriteLine("Finish disconnect:" + _util.VpnName);

            //在NAT下使用VPN,断开VPN时会导致原网络断开,需要重启网卡,暂时没有找到更好的解决方法
            if (!string.IsNullOrEmpty(NetInterface))
            {
                NetInterfaceUtils.ChangeNetworkConnectionStatus(false, NetInterface);
                Thread.Sleep(2000);
                NetInterfaceUtils.ChangeNetworkConnectionStatus(true, NetInterface);
                Thread.Sleep(2000);
            }

            Console.WriteLine("Trying to connect Vpn:" + _util.VpnName);
            _util.TryConnectVpn();
            Thread.Sleep(1000);
            Console.WriteLine("Finish connect:" + _util.VpnName);
        }