Usare await nel Main in C#
Oggi stavo giocando con una libreria che richiede la chiamata ai metodi con await.
Ma in C# non si possono usare direttamente nel Main, e non è possibile rendere il Main async.
Quindi come si può aggirare il problema?
Ecco un esempio:
using System;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
MainAsync(args).GetAwaiter().GetResult();
}
static async Task MainAsync(string[] args)
{
// UTILIZZO DI await
}
}
}
A me ha funzionato senza problemi.
Enjoy!
c# await async getawaiter
Commentami!