Hello,
If you have a Async/Await method to perform long run operation.
And you added the <ActivityIndicator x:Name="MyAi" />
in your layout.
If you have a button, then click the button to download file. Before you start download the file, set IsRunning = true;, If downloaded operation finished (I add Task.Delay(6000)
to simulate downloaded operation), use ContinueWith
and set IsRunning = false
to make the <ActivityIndicator >
disappear the in the MainThread.
private async void DownloadBtn_Clicked(object sender, EventArgs e)
{
MyAi.IsRunning = true;
await Task.Delay(6000).ContinueWith(t => {
MainThread.InvokeOnMainThreadAsync(() => {
MyAi.IsRunning = false;
});
});
}
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.