I've been using ShowLoading and HideLoading throughout my app and they all work as intented however for one implementation I needed to show loading on click on a StackLayout which I have implemented like
CheckOutStack.GestureRecognizers.Add((new TapGestureRecognizer { Command = new Command((o) => { App.UserDialog.ShowLoading("sdsa"); Task y = Task.Run(() => { for (int x = 0; x < 10000; x++) Debug.WriteLine("int x = " + x); }); y.Wait(); App.UserDialog.HideLoading(); using (App.UserDialog.Loading("Loading...")) { Debug.WriteLine("Start"); Task.Delay(9000); Debug.WriteLine("End"); }...
on both ShowLoading or Loading didn't bring up the loading overlay. My suspicion why it isn't working is because I'm doing it on a command because it has been working before outside of a command. However besides that I have no justification as to why.
Any help or discussion on the topic would be greatly appreciated
For me it's working for, if my code inside is asynchronous - like:
using (UserDialogs.Instance.Loading("Loading...")) { async InvokeApi(); }
You aren't awaiting your task and then you go straight in .Wait which is blocking the main thread, so the loader can't get itself displayed.
Answers
For me it's working for, if my code inside is asynchronous - like:
You aren't awaiting your task and then you go straight in .Wait which is blocking the main thread, so the loader can't get itself displayed.
Ah i see. I was under the impression starting a new task would be async and not block the main thread... makes me think i'm doing a whole bunch of stuff wrongly now but thanks guys that was a lot of help.
UserDialogs.Instance.Loading("Loading");
Some API call
UserDialogs.Instance.HideLoading();
Is this correct way or must required async call?