Unable to display alert after modal popup

Phunction 261 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.

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,805 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,185 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 34,226 Reputation points Microsoft Vendor
    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

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.