C#ip pinger工具帮助视觉工作室 [英] C# ip pinger tool help visual studios

查看:89
本文介绍了C#ip pinger工具帮助视觉工作室的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用这个代码时遇到了一些问题,它在我的项目中一直给我99个错误我是C#的新手并且可以使用一些帮助来知道为什么这里不起作用是代码





i am having some trouble with this code it keeps giving me 99 errors in my project i am new to C# and could use some help to know why this is not working here is the code


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
using System.Net;



namespace Ping
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Thread th;
        private void Form1_Load(object sender, EventArgs e)
        {
          
        }

        private void button1_Click(object sender, EventArgs e)
        {
            th = new Thread(thread);
            th.Start;
        }
        public void thread1();
      {

          try
        {
           string(command = "/c ping " + textbox.Text;
            ProcessStartInfo procStartInfo = new ProcessStartInfo("CMD", command);
        Process proc = new Process();
        Proc.StartInfo = new Proc.StartInfo;
            Proc.StartInfo.WindowsStyle = ProcessWindowStyle.Hidden;
            proc.StartInfo.RedirectStandardOutput = true;
            proc.StartInfo.RedirectStandardInput = true;
            proc.Startinfo.RedirectStandardError = true;
            proc.StartInfo.UseshellExecute = false;
            proc.Startinfo.CreateNoWindow = true;
            proc.OutputDataReceived += new DataReceivedEventHandler(proc_OutputDataReceived);
            Proc.Start();
            proc.BeginOutputReadLine();
            proc.WaitForExit();
      
    }
        catch (Exception)
            {

     
    }
}





我的尝试:



i试图找到其他来源但却找不到任何来源!



What I have tried:

i have tried finding other sources but could not find any!

推荐答案

- '99错误是什么意思' - 这是计数吗? (记住,我们无法看到你的屏幕,阅读你的想法等等)

- 不工作意味着什么?好吧,我们可以猜测没有编译,但你能看出这是一个如此模糊的陈述,它无法帮助我们帮助你吗?

- 你有什么特别的理由要做ping吗?这条路' ?也就是说,如果你是一个初学者,它需要付出很多努力才能获得线程代码和外部流程代码来激活ping工作,更不用说从流程中捕获结果了(gawd,不要让我开始,那就是那个,那就是一本书本身 - 有99种不正确的方法,1种方式(也许是2种)正确的方式)



所以,我给你的建议是的,除非你真的必须这样做,选择一个更简单的选项 - 如何 Ping.Send方法(IPAddress)(System.Net.NetworkInformation) [ ^ ]或 Ping类(System.Net.NetworkInformation) [ ^ ]例如?



顺便说一下,第二个链接包括ping异步示例(对于响应式ui更好) - 如果从ping回调处理程序更新UI,则需要小心谨慎
- what do you mean by '99 errors' - is that the count ? (remember, we cant see your screen, read your mind etc)
- what does 'not working mean' ? ok, we can guess 'not compiling', but can you see how that's such a vague statement it cant help us to help you ?
- Is there a particular reason why you want to do the ping 'this way' ? ie, if you are a beginner, its a lot of effort to get threading code and 'external' process code to fire a ping working correctly, let alone, capturing the results from the process (gawd, dont get me started on that, thats a book unto itself - theres 99 ways of doing it incorrectly, 1 way (maybe 2) way(s) of getting it right)

So, my suggestion unto you, is, unless you really have to do it this way, pick a simpler option - how about Ping.Send Method (IPAddress) (System.Net.NetworkInformation)[^] or Ping Class (System.Net.NetworkInformation)[^] for example ?

btw, the 2nd link includes the ping async example (much better for a responsive ui) - you would need to take all care if you update your UI from the ping callback handler


这篇关于C#ip pinger工具帮助视觉工作室的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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