public static bool LinkVpnAsync(string serverIp, string userId, string password, int times = 30) { if (string.IsNullOrEmpty(serverIp) || string.IsNullOrEmpty(userId) || string.IsNullOrEmpty(password)) { return(false); } var vpnModel = new VpnModel() { ServerIp = serverIp, UserName = userId, PassWord = StringHelper.Base64Decode(password), VpnProtocol = "L2TP" }; do { VpnService.Connect(ref vpnModel); //Global.Linked = await TestInternetAsync(); //if (Global.Linked) //{ // return true; //} Thread.Sleep(1000); if (TestInternet(5)) { return(true); } times--; } while (times > 0); return(false); }
public static void DisconnectVpn() { VpnService.Abort(); //Global.Linked = false; }