I am wondering if the following methods in the Main
method implement async/await
modifier correctly as to imposing the asynchronous programming in my C#
.NET Core
console application.
Main method:
static void Main(string[] args)
{
//...
MyTask_1_RunAsync(dbConnectionString).Wait();
MyTask_2_RunAsync(dbConnectionString).Wait();
//...
}
Other methods:
static async Task MyTask_1_RunAsync(string dbConnectionString)
{
//....
var content = new StringContent(paramObj, Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.PostAsync(client.BaseAddress, content);
if (response.IsSuccessStatusCode)
{
string jsonString = await response.Content.ReadAsStringAsync();
}
//...
}
static async Task MyTask_2_RunAsync(string dbConnectionString)
{
//....
var content = new StringContent(paramObj, Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.PostAsync(client.BaseAddress, content);
if (response.IsSuccessStatusCode)
{
string jsonString = await response.Content.ReadAsStringAsync();
}
//...
}