views:

139

answers:

1

I'm trying to send two events to the main window so that I can show some kind of animation that will let the user know that I'm updating the data.

This is an ObservableCollection object so the OnPropertyChanged is immediately picked up by the bindings on the main window. The sleep is only in there so that the user can see the animation.

However, the first OnPropetyChanged is never seen. I'm assuming this is because we're in a single thread here and the timer_Tick has to finish before the GUI updates. Any suggetions? In VB6 land we would use a DoEvents or a Form.Refresh.

Thanks!

private void timer_Tick(object sender, EventArgs e)
    {
        Loading = "Before: " + DateTime.Now.ToString();
        OnPropertyChanged("Loading");

        LoadData();
        Thread.Sleep(1000);

        //Loading = Visibility.Hidden;
        Loading = "After: " + DateTime.Now.ToString();
        OnPropertyChanged("Loading");           
    }
A: 

Well C# has an Application.DoEvents but I wouldn't recommend using it unless absolutely necessary.

Have you tried wrapping your OnPropertyChanged call in a Dispatcher.Invoke?

Charlie
You wouldn't want to help me with the code on that would you? ;)
LSTayon
N/MThis is what I used:queryTimer.Dispatcher.Invoke(DispatcherPriority.Normal, new ThreadStart(delegate { OnPropertyChanged("Loading"); }));I'm in a class so I can't use the this.Dispatcher call.When I step through the code, after the first Dispatch the widow goes black and then only refreshes after I step out of the timer tick...
LSTayon