Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Why would someone delay Navigation.PushAsync / Navigation.PopAsync with Device.StartTimer?

$
0
0

Hi, I am new to Xamarin Forms and I have inherited an app that does something like:

        void BtnSubmit_Clicked (object s, EventArgs a)
        {
            if (editing) {
                Device.StartTimer (TimeSpan.FromSeconds (1), () => {
                    Navigation.PopAsync ();
                    return false;
                });
            } else {
                Device.StartTimer (TimeSpan.FromSeconds (1), () => {
                    Navigation.PushAsync (new OurCustomPage ());
                    Device.StartTimer (TimeSpan.FromSeconds (2), () => {
                        Navigation.RemovePage (this);
                        return false;
                    });
                    return false;
                });
            }
        }

I find this code confusing and want to rewrite it to:

        async void BtnSubmit_Clicked (object s, EventArgs a)
        {
            if (editing)
            {
               await Navigation.PopAsync();
            } else {
                await Navigation.PushAsync(new OurCustomPage ());
                Navigation.RemovePage(this);
            }
        }

Could anyone tell me if that would be a problem? I have been told that sometimes delays are necessary to prevent the app from freezing / choking on UI changes but i am not sure how to create test conditions that would reproduce any problem with my desired approach.

Thank you in advance!


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>