CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2015
    Posts
    4

    Why am I getting a TIMEOUT error?

    When I run this app, it is suppose to ping each of those websites 4 times and save the results in a .csv file. But I keep getting either an exception handler error or the timeout error. What am I doing wrong? Please help me.

    Code:
     
    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);
    					    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");
    					    }
                        }
    				}
    			}
    		}
    	}
    }

  2. #2
    Join Date
    Mar 2001
    Posts
    2,527

    Re: Why am I getting a TIMEOUT error?

    Try to ping those addresses from the command-line.

    I bet your ISP won't allow it or your corporate network blocks it.

    To verify that ping local machines on your network.

    Now the Exceptions may actually be other bugs you have introduced, but the timeouts
    most likely are due to above mentioned reasons.
    ahoodin
    To keep the plot moving, that's why.

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,495

    Re: Why am I getting a TIMEOUT error?

    How do you know you have a timeout error since you are using an empty catch block? Maybe you have another error?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured