Async Dialog

Hey. Ich am trying to open a Busy-Dialog, while i am async verifying whether my login data is correct.

Following the source code here: Blazor Dialog component, i implemented the following:

	async Task OnLogin(LoginArgs args)
	{

		InvokeAsync(async () =>
		{
			var myStateProv = authenticationStateProvider as AuthStateProvider;
			var isValid = await myStateProv.VerifyAndStoreUser(args.Username, args.Password);
            if (!isValid) { }
			// Close the dialog
			dialogService.Close();
	});

		await BusyDialog("Logging in ...");

		var returnUrl = navigationManager.QueryString("returnUrl");
		navigationManager.NavigateTo(returnUrl ?? "");
	}

This however won't open the dialog, until after my task has finished. The dialog pops up shortly and dissapears immediatly.
If i replace the call with a Task.Delay(2000), the dialog will open and close just fine. How can i get this to work, so that the Busy-Dialog is shown, while the data is verified?

Best Regards

	async Task OnLogin(LoginArgs args)
	{
		var myStateProv = authenticationStateProvider as AuthStateProvider;

		InvokeAsync(async () =>
	{
		// Simulate background task
		await Task.Delay(10);

		var isValid = await myStateProv.VerifyAndStoreUser(args.Username, args.Password);
		if (!isValid) { }

		// Close the dialog
		dialogService.Close();
	});

This works. But why?

You can check my reply here: Button is not reacting to IsBusy or reacting too late - #2 by korchev I think it is the same situation - Blazor does not refresh the UI unless given a chance.

Hey, thank you so much for your reply!
This code works:

	async Task OnLogin(LoginArgs args)
	{

		InvokeAsync(async () =>
		{
			await Task.Yield();

			var myStateProv = authenticationStateProvider as AuthStateProvider;
			var isValid = await myStateProv.VerifyAndStoreUser(args.Username, args.Password);
			if (!isValid) { }

			dialogService.Close();
		});

		await BusyDialog("Logging in...");
}