loading
open in
main.cs
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
29
30
31
32
33
34
using System;
using System.Threading;
using System.Threading.Tasks;
using System.Net;

class MainClass {
  private static AutoResetEvent _autoResetEvent = new AutoResetEvent(false);

  public static void Main (string[] args) {

    MainAsync(args);

    Console.WriteLine("Main thread is working.");

    _autoResetEvent.WaitOne();
  }

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

    _autoResetEvent.Set();
  }
}

public static class CustomDnsWithTAP
{
    public static Task<IPHostEntry> GetHostEntryAsync(string hostNameOrAddress)
    {
        return Task.Run(() => Dns.GetHostEntry(hostNameOrAddress));
    }
}
Mono C# compiler version 4.0.4.0