Unable to display alert after modal popup

Phunction 301 Reputation points
2025-01-08T17:19:31.36+00:00

I have an issue I am unable to solve.

In this code:

var popupPage = new myPopup();

var taskCompletionSource = new TaskCompletionSource<bool>();

// Set up an event to resolve the task when the modal is dismissed
popupPage.Disappearing += (s, args) =>
{
    taskCompletionSource.TrySetResult(true);
};

// Push the modal and await its dismissal
await this.Navigation.PushModalAsync(popupPage);
await taskCompletionSource.Task;
await Task.Delay(100);

await MainThread.InvokeOnMainThreadAsync(async () =>
{
    await DisplayAlert("Update", "The file needs to be updated to the latest version. Do you wish to do this now?", "Yes", "No");
});

The popup is awaited properly and will not continue until I close the popup, however when it hits teh DisplayAlert(), the method just ends, there is no exeception thrown (I do have this enclosed in a try/catch) and there is no alert displayed.

Developer technologies .NET .NET MAUI
Developer technologies C#
{count} votes

Accepted answer
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 36,436 Reputation points Microsoft External Staff
    2025-01-10T07:41:29.35+00:00

    Hello,

    If I do an await Task.Delay(2000) then it will work.

    Glad you solved the problem.

    Is Maui really this slow?

    This is because the alert and the popup page both call the Model-View-Controller on iOS, call popup twice and it is a time-consuming operation.

    Best Regards,

    Wenyan Zhang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.