namespace ConsoleTests
{
class Program
{
static void Main(string[] args)
{
var content = Get(args[0]);
}
public static async Task Get(string url)
{
using (HttpClient client = new HttpClient()) {
HttpResponseMessage response = await client.GetAsync(url);
//Breakpoint set here
}
}
}
}
The reason for this is that when Main exits the program exists, and any outstanding async operations are cancelled along with it. This can be solved by changing
var content = Get(args[0]);to
var content = Get(args[0]).Wait();to block Main from exiting.
No comments:
Post a Comment