Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 断开而不断开?_C# - Fatal编程技术网

C# 断开而不断开?

C# 断开而不断开?,c#,C#,对于我的一些项目,我必须禁用我的连接大约5秒钟,然后再次启用它 我现在怎么做(这不是最好的解决方案,但我使用的是Windows VPN): 我已经设置了一个VPN,它不允许任何互联网通过,这使我有点断开连接,但比Wi-Fi重新连接更快 所以我基本上想知道一种断开连接的方法,比如连接到一个坏掉的VPN(没有Wi-Fi) 在C#代码中 这可能吗?采取以下措施: 使用netsh命令,可以启用和禁用“局域网连接” interfaceName is “Local Area Connection”.

对于我的一些项目,我必须禁用我的连接大约5秒钟,然后再次启用它

我现在怎么做(这不是最好的解决方案,但我使用的是Windows VPN):

  • 我已经设置了一个VPN,它不允许任何互联网通过,这使我有点断开连接,但比Wi-Fi重新连接更快
所以我基本上想知道一种断开连接的方法,比如连接到一个坏掉的VPN(没有Wi-Fi)

在C#代码中

这可能吗?

采取以下措施:

使用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();
    }

嗯,威尔辩护地说:)你的意思是“会尝试”?一定要这样做:)是的,我试过这样做:启用(“本地连接”);im可能是错误的,但该解决方案是否仅适用于以太网?我不知道我在工厂有一个本地连接。试试这个用电缆,不能马上用那个自动取款机,如果它用电缆工作的话也可以:)