Share via

How to close the Popup after session out?

Sowndarrajan Vijayaragavan 470 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?

Developer technologies | .NET | .NET Multi-platform App UI

Answer accepted by question author

  1. Alessandro Caliaro 4,206 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

    Was this answer helpful?


0 additional answers

Sort by: Most helpful

Your answer

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