How to perform long run operation with ActivityIndicator

Dani_S 2,886 Reputation points


How to perform long run operation with ActivityIndicator?


A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,977 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 69,386 Reputation points Microsoft Vendor


    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.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.

    1 deleted comment

    Comments have been turned off. Learn more