how to do a loading screen during an async await process in.net #18717
Replies: 4 comments
-
My approach to this has been the following: Using .NET MAUI Community Toolkit I have created a Popup with just an ActivityIndicator. Then just before the time consuming task I show the Popup and close it right after the the task has finished. In the last release of .NET MAUI Community Toolkit it includes a service you can register within your DI container but I haven't use it because makes it hard to close the Popup outside the Popup itself, like with an undetermined time task. |
Beta Was this translation helpful? Give feedback.
-
@tatoadsl Can you, please, provide an example? I guess your time consuming task is being executed on a background thread otherwise the ActivityIndicator will get freezed, am I correct? |
Beta Was this translation helpful? Give feedback.
-
Hi @mihaimyh It is kinda easy to make it work using a PopUp. Here is the call to the pop up and the long running task called once the popup has been shown:
I have created a PopupService to help show the popup. I haven't yet use the PopupService included in the .NET MAUI Community Toolkit that now allows to close the popup through the service.
and the Popup is defined like this:
It is working good for me, hope that the example is useful. |
Beta Was this translation helpful? Give feedback.
-
I have found the following library useful if you're app is mobile only: |
Beta Was this translation helpful? Give feedback.
-
Before everything forgive me for the bad english and the mistakes i'd could do in the code I'm just an student and I cannot find the solution to my problem, or I don't understand it, anywhere.
So, I have a Class, "ClienteService" where I load a List of Cliente.
namespace Pantalla_Cliente { class ClienteService { public async Task<List<Cliente>> GetClientesAsync() { string url = Program.rutaBase + Rutas.cliente; string response = await ApiClient.GetRequestAsync("GET", url, Program.token); List<Cliente> listClientes = JsonSerializer.Deserialize<List<Cliente>>(response); return listClientes; } } }
I have a form where I get the list and with the info I got I create "cards" with the info of the customer.
` private async void ObtenerClientes()
{
List listCliente = await clienteService.GetClientesAsync();
CrearPanelesClientes(listCliente);
}
The problem is that when I show the list, there's an small amount of time. less than 0.5s, so I want a loading screen for that time, because with 30 customers maybe is 0.2s, but if we get more customers, the time will increase.
I tried with a pictureBox making visible before " List listCliente = await clienteService.GetClientesAsync();" and after that making it invisible again. But it doesn't show the gif, the only way I can see the gif if I put a delay of 3s, but I dont want to put manually the time I want to wait
Beta Was this translation helpful? Give feedback.
All reactions