What is the key differences between those two methods?
First method that use Task<TResult>
:
public async Task GetTaskDataFromAPI()
{
using (var httpClient = new HttpClient())
{
using (var response = await httpClient.GetAsync("https://fakeapi/users"))
{
string apiResponse = await response.Content.ReadAsStringAsync();
Console.WriteLine(apiResponse);
}
}
}
And second method that use simple void
:
public async void GetVoidDataFromAPI()
{
using (var httpClient = new HttpClient())
{
using (var response = await httpClient.GetAsync("https://fakeapi/users"))
{
string apiResponse = await response.Content.ReadAsStringAsync();
Console.WriteLine(apiResponse);
}
}
}
I can't notice the difference when I'm debugging this code. Why and when those methods should be used and what is the main differences between them?