程序一直在冻结 [英] Program keeps freezing

查看:101
本文介绍了程序一直在冻结的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个内置CMD的程序。它有预设的ipconfig -all按钮等等。但是,Everything工作正常但是当我按下按钮时程序冻结。

Im making a program with a built in CMD. It has preset buttons for ipconfig -all and so forth. However, Everything works fine but when i press the buttons the program freezes.

Private Sub btnIpConfig_Click(sender As Object, e As EventArgs) Handles btnIpConfig.Click
    Dim proc As New Process
    proc.StartInfo.FileName = "CMD.exe"
    proc.StartInfo.Arguments = "/k ipconfig /all"
    proc.StartInfo.CreateNoWindow = True
    proc.StartInfo.UseShellExecute = False
    proc.StartInfo.RedirectStandardOutput = True
    proc.Start()
    proc.WaitForExit()

    Dim output() As String = proc.StandardOutput.ReadToEnd.Split(CChar(vbLf))
    For Each ln As String In output
        AppendOutputText(ln & vbNewLine)
    Next
End Sub





我有办法解决这个问题吗?



Is there a way I can fix this?

推荐答案

我不明白为什么你需要shell /使用CMD来运行ipconfig - 你需要的所有信息都是 https://msdn.microsoft.com/en-us/library/system.net.networkinformation(v = VS.100)的.aspx [ ^ ]即System.Net.NetworkInformation命名空间



例如



I don't see why you need to shell out / use CMD to run ipconfig - all the information you need is https://msdn.microsoft.com/en-us/library/system.net.networkinformation(v=vs.100).aspx[^] ie the System.Net.NetworkInformation namespace

eg

System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0].GetIPProperties().DnsAddresses[0]





如果你绝对必须通过ipconfig来做,我会考虑产生一个后台工作者做CMD的东西



If you absolutely must do it via ipconfig , I'd consider spawning off a background worker to do the CMD stuff


你永远不需要使用CMD.EXE。这是一个专为交互式使用而设计的命令解释器。它根本没有帮助你。你需要直接用CMD.exe执行你想要执行的东西。



换句话说,如果你能做到

You never ever needs to use CMD.EXE. This is a command interpreter designed for interactive use. It does not help you at all. You need to execute what you want to execute with CMD.exe directly.

In other words, if you can do
System.Diagnostic.Process.Start("CMD.EXE", "/k do something");
' Makes no sense at all!



你永远不应该这样做。相反,这样做:


you should never actually do it. Instead, do this:

<pre lang="vb">System.Diagnostic.Process.Start("do", "this and this and that");
' Isn't that obvious?!





想想你在做什么很好。使用CMD.EXE反映了非工程用户的心理。



-SA


这篇关于程序一直在冻结的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆