I am trying to connect to Azure AD and I am using this code.
try
{
var clientCredential = new ClientCredential(_clientId, _clientSecret);
var authCon
the process is simply killed. No exception is thrown, nothing.
I assume that you are running this in a Console application, and that your top-level code would look something like this:
static void Main()
{
MyMethodAsync();
}
In which case, the main method would in fact exit, since it is not waiting for your asynchronous code to complete.
One way to work with async
in Console applications is to block in the Main
method. Normally, you want to go "async all the way", but a Console app's Main
method is an exception to this rule:
static void Main() => MainAsync().GetAwaiter().GetResult();
static async Task MainAsync()
{
// Original code from Main, but adding any necessary `await`s.
await MyMethodAsync();
}
Update: Don't use async void; use async Task
instead:
static async Task ImportLicenceAsync()
{
await InsertToDbAsync();
}
public async Task InsertoDbAsync()
{
var x = await GetSPAsync();
}