为什么我会收到超时错误或异常处理程序错误?

Why am I getting a TIMEOUT error, or an exception handler error?

当我 运行 这个程序时,假设对每个网站执行 4 次 ping 操作并将结果(网站和 return 时间以毫秒为单位)保存在 .csv 文件中。但是我收到异常处理程序或超时错误。有人可以帮帮我吗? 这是我拥有的:

using System;
using System.Collection.Generic;
using System.IO;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using Threading.Teask;

namespace PingApp
{
    class Program
    {
        static void Main(string[] args)
        {
            List<string> lstWebSites = new List<string>();
            lstWebSites.Add("www.yahoo.com");
            lstWebSites.Add("www.att.com");
            lstWebSites.Add("www.verizon");
            string filename = @"PingLog.csv";
            {
                using (var writer = new StreamWriter(filename, true)) 
                {
                    foreach(string website in lstWebSites)
                    {
                        writer.WriteLine(website, lstWebSites);
                        try
                        {
                            Ping myPing = new Ping();
                            PingReply reply = myPing.Send(website, 1000);
                            if (reply != null)
                            {
                                Console.WriteLine("{0}, {1}", reply.Address, reply.RoundtripTime);
                            }
                        }                   
                        catch
                        {
                            Console.WriteLine.("ERROR: You have some TIMEOUT issue");
                        }
                    }
                }
            }
        }
    }
}
lstWebSites.Add("www.verizon");

会超时。我想你想要

lstWebSites.Add("www.verizon.com");

好的,我对代码做了一些修改。我删除了

writer.WriteLine(website, lstWebSites);

并添加了

writer.WriteLine(website + "," + reply.Address.ToString() + "," + reply.RoundtripTime);

代替Console.WriteLine("{0}, {1}", reply.Address, reply.RoundtripTime); 现在结果看起来像

每个站点只 ping 一次。