0

I am working on Xamarin forms for our iOS App. I have a requirements to show a dialog box after a certain period of time and show user an option to continue his session or logout.
I am planning to run a timer after user login to the app then check if user already reached certain number of hours. Is there a best way to do the timer? I tried the below method but for some reason it freezes the screen.

 Device.StartTimer(new TimeSpan(0, 0, 60), () =>
            {
                // do something every 60 seconds
                Device.BeginInvokeOnMainThread(() =>
                {
                    // interact with UI elements
                });
                return true; // runs again, or false to stop
            });
ramdev
  • 137
  • 1
  • 9
  • If it "freezes the screen", then whatever you do in "// interact with UI elements" takes too long. Do anything lengthy **before** `BeginInvoke..`. Prepare needed values. Then quickly make changes to UI elements inside `BeginInvoke..`. If need more advice, then show the actual code. – ToolmakerSteve May 18 '22 at 17:59
  • @ToolmakerSteve, I posted the actual code here. https://stackoverflow.com/questions/72306234/timer-in-xamarin-doesnt-honor-the-time-you-set – ramdev May 19 '22 at 14:31

0 Answers0