Skip to content

Instantly share code, notes, and snippets.

@kenanhancer
Created September 27, 2018 22:42
Show Gist options
  • Save kenanhancer/a0e67bb9099296d8b21af531533b67ed to your computer and use it in GitHub Desktop.
Save kenanhancer/a0e67bb9099296d8b21af531533b67ed to your computer and use it in GitHub Desktop.
TaskBasedAsynchronousPattern_TAP created by kenanhancer - https://repl.it/@kenanhancer/TaskBasedAsynchronousPatternTAP
using System;
using System.Threading.Tasks;
using System.Net;
class MainClass {
public static void Main (string[] args) {
MainAsync(args);
Console.WriteLine("Main thread is working.");
Console.ReadLine();
}
public static async Task MainAsync(string[] args)
{
IPHostEntry result = await CustomDnsWithTAP.GetHostEntryAsync("www.kenanhancer.com");
Console.WriteLine($"Worker thread is working and result is {result.HostName}");
}
}
public static class CustomDnsWithTAP
{
public static Task<IPHostEntry> GetHostEntryAsync(string hostNameOrAddress)
{
return Task.Run(() => Dns.GetHostEntry(hostNameOrAddress));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment