【发布时间】:2015-12-21 15:02:58
【问题描述】:
对于我的一些项目,我必须禁用我的连接大约 5 秒钟,然后再次启用它。
我现在该怎么做(这不是最好的解决方案,但我使用的是 Windows VPN):
- 我设置了一个 VPN,它不会让任何互联网低谷,这让我有点断开连接,但比重新连接 Wi-Fi 更快。
所以我基本上想知道一种断开连接的方法,例如连接到损坏的 VPN(无 Wi-Fi)。
在 C# 代码中。
这可能吗?
【问题讨论】:
标签: c#
对于我的一些项目,我必须禁用我的连接大约 5 秒钟,然后再次启用它。
我现在该怎么做(这不是最好的解决方案,但我使用的是 Windows VPN):
所以我基本上想知道一种断开连接的方法,例如连接到损坏的 VPN(无 Wi-Fi)。
在 C# 代码中。
这可能吗?
【问题讨论】:
标签: c#
拿a look:
使用 netsh 命令,您可以启用和禁用“本地连接”
interfaceName is “Local Area Connection”.
static void Enable(string interfaceName)
{
System.Diagnostics.ProcessStartInfo psi =
new System.Diagnostics.ProcessStartInfo("netsh", "interface set interface \"" + interfaceName + "\" enable");
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo = psi;
p.Start();
}
static void Disable(string interfaceName)
{
System.Diagnostics.ProcessStartInfo psi =
new System.Diagnostics.ProcessStartInfo("netsh", "interface set interface \"" + interfaceName + "\" disable");
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo = psi;
p.Start();
}
【讨论】: