我必须在 ListBox 中显示我的 LAN 的所有 IP 地址。当我试图将其绑定为空时。
// 代码
Process netUtility = new Process();
netUtility.StartInfo.FileName = "net.exe";
netUtility.StartInfo.CreateNoWindow = true;
netUtility.StartInfo.RedirectStandardOutput = true;
netUtility.StartInfo.UseShellExecute = false;
netUtility.StartInfo.RedirectStandardError = true;
netUtility.Start();
StreamReader streamReader = new StreamReader(netUtility.StandardOutput.BaseStream);
string line = "";
while ((line = streamReader.ReadLine()) != null)
{
if (line.StartsWith("\\"))
{
ListBox1.Items.Add(line.Substring(2).Substring(0, line.Substring(2).IndexOf(" ")).ToUpper());
}
}
streamReader.Close();
netUtility.WaitForExit(1000);
我哪里错了?