error while loading a ProgressRing (Mahapps)

0

I have a ProgressRing in a Page in WPF that needs to be displayed while the Grid is loading (Purpose: Show the user who is loading) and then be deactivated when the load of the Grid is completed. But it is giving this error:

 public ClienteListPage()
        {
            InitializeComponent();
            carregar();
        } 
        
        public void carregar()
        {
            prProgresso.IsActive = true;
            Task.Factory.StartNew(() =>
            {
                DataContext = App.container.GetService<IClientesListarController>();
            }).ContinueWith(task =>
            {
                prProgresso.IsActive = false;
                if (task.IsFaulted)
                {
                    Console.WriteLine("{0} Exception caught.", task.Exception);
                    MessageBox.Show("Error");
                }
            }, System.Threading.CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());
        }

Does anyone know how to help me?

    
asked by anonymous 26.12.2017 / 18:22

1 answer

0

You are having problems because you are running this on another thread.

.NET has a class called BackGroundworker , which provides methods for report the progress of the thread in an event. The event is automatically called in the topic that created the BackgroundWorker (usually the UI segment).

Use this event " ProgressChanged " and update the progress bar in this event handler.

    
27.12.2017 / 12:11