1

I'm working in an application that takes its own content from a server. Each X seconds has to check if there have been changes and, if so, to refresh the related screens.

I'm trying to refresh the UI from the thread that checks if any changes have been uploaded, but the thing is that the code is executed but the view it's not refreshed.

Here's a sample of the code:

//Class that checks changes in server

await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
                () =>
                {
                    //Page that has to refresh its UI
                    Home h = new Home();
                    h.RefreshData(update);
                });
                break;

//HOME Page
public void RefreshData(PushElement update)
        {
            _source.Clear(); //ObservableCollection<UserControl>, is the ItemsSource of the Main ListView of the Home page
            NotifyPropertyChanged();
            setContentFromProps("URL_HOME"); //Function that fills back the ListView
        }

//Property bound to ItemsSource in the XAML
    public ObservableCollection<UserControl> Source
            {
                get
                {
                    return _source;
                }
                set
                {
                    _source = value;
                    NotifyPropertyChanged();
                }
            }

If I put a breakpoint, the code is executed but the UI it's never refreshed. I have tried many ways to do it, but unsuccessfully... How could I achieve it?

Thanks in advance!

Eva FP
  • 775
  • 9
  • 24
  • Possible duplicate of [How to update the GUI from another thread in C#?](http://stackoverflow.com/questions/661561/how-to-update-the-gui-from-another-thread-in-c) – AntiTcb Apr 25 '16 at 14:54
  • 4
    You are creating a new instance of Home and refreshing the new instance. You should already have an instance of Home and the dispatcher should simply call home.RefreshData(data). – ManOVision Apr 25 '16 at 15:04
  • Thanks @ManOVision!!! It has solved the issue – Eva FP Apr 27 '16 at 09:19

0 Answers0