tags:

views:

86

answers:

1

Here's a piece of code I'm using:

public void Start() {

    Dns.BeginGetHostEntry("www.google.com", new AsyncCallback(Stop), "Lookin up Google");
}

public void Stop(IAsyncResult ar) {
    IPHostEntry ie = Dns.EndGetHostEntry(ar);
    Console.WriteLine(ie.HostName);

    foreach(string adres in ie.Aliases) {
        Console.WriteLine(adres);
    }
}

And it returns nothing. It doesn't seem to work and I get no errors.

If I use the non-asynchronous methode: Dns.GetHostEntry("www.google.com");, that does work.

I don't get what's wrong here.

+1  A: 

I just ran it and it worked fine

namespace test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            Start();
        }

        public void Start()
        {

            Dns.BeginGetHostEntry("www.google.com", new AsyncCallback(Stop), "Lookin up Google");
        }

        public void Stop(IAsyncResult ar)
        {
            IPHostEntry ie = Dns.EndGetHostEntry(ar);
            Console.WriteLine(ie.HostName);

            foreach (string adres in ie.Aliases)
            {
                Console.WriteLine(adres);
            }
        }
    }
}
dirtmike
Are you sure you are calling Start? The output I specifically got was www.l.google.com
dirtmike
myeah, it's working now too. Wouldn't work a while ago. Also, dirtmike, that's the expected output.
WebDevHobo