How to close the Popup after session out?

Sowndarrajan Vijayaragavan 450 Reputation points
2023-07-18T13:15:37.16+00:00

In App.xaml.cs

Timer IdleTimer = new Timer(new TimeSpan(00, 10, 00));  //HH,MM,SS    
#region related to automatic logout after 30 mins
    //Changes related to automatic logout after 30 mins
    async void Idleimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
    {
        if (MainThread.IsMainThread)
            GotoLogin();
        else
            MainThread.BeginInvokeOnMainThread(GotoLogin);
    }

    public void ResetIdleTimer()
    {
        IdleTimer.Stop();
        IdleTimer.Start();
    }

    void GotoLogin()
    {
        // Code to run on the main thread
        //this.Quit();
        MainPage = new LoginPage();
    }
    #endregion


In MAUIProgram.cs

 #region related to automatic logout after 30 mins
        //Changes related to automatic logout after 30 mins
        builder.ConfigureLifecycleEvents(events =>
        {
#if WINDOWS
                events
                    .AddWindows(windows => windows
                        .OnPlatformMessage((window, args) =>
                        {
                            if (args.MessageId == Convert.ToUInt32("0x0086", 16) ||
                                args.MessageId == Convert.ToUInt32("0x0020", 16) ||
                                args.MessageId == Convert.ToUInt32("0x0021", 16) )
                            {
                                (App.Current as App).ResetIdleTimer();
                            }
                        }));
#endif
        });
        #endregion

Need solution to close the popup as well?

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,900 questions
{count} votes

Accepted answer
  1. Alessandro Caliaro 4,186 Reputation points
    2023-07-18T13:23:09.5733333+00:00

    You can send a message using WeakReferenceMessenger. When you open a popup, the popup should register to this message, and when receive it. execute the "close" to close the popup.

    https://www.c-sharpcorner.com/article/net-maui-good-bye-messagingcenter-welcome-weakreferencemanager/#:~:text=In.NET%20MAUI%2C%20messages%20are%20represented%20by%20a%20class,its%20instance%20is%20exposed%20by%20the%20Default%20property.

    I think it is not possible to close DisplayAlert programmatically so you should convert all DisplayAlert with Community Toolkit maui popup control


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.