1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
private async void ButtonSearchHostAsync_OnClick(object sender, EventArgs e)
{
ButtonOldPatternInteractionAsync.IsEnabled = false;
TextBoxOldPatternInteractionResults.Text = string.Join(", ", (await GetHostEntryAsync("www.google.com")).AddressList.ToList());
ButtonOldPatternInteractionAsync.IsEnabled = true;
}
public static Task<IPHostEntry> GetHostEntryAsync(string hostNameOrAddress)
{
var taskCompletionSource = new TaskCompletionSource<IPHostEntry>();
Dns.BeginGetHostEntry(hostNameOrAddress, (asyncResult) =>
{
try
{
IPHostEntry result = Dns.EndGetHostEntry(asyncResult);
taskCompletionSource.SetResult(result);
}
catch (Exception e)
{
taskCompletionSource.SetException(e);
}
}, null);
return taskCompletionSource.Task;
} |
Partager