开发者_如何学GoHere'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.
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);
}
}
}
}
精彩评论