WPF -- Event Threading, GUI updating question

Posted by LSTayon on Stack Overflow See other posts from Stack Overflow or by LSTayon
Published on 2009-08-07T22:20:02Z Indexed on 2010/04/04 1:03 UTC
Read the original article Hit count: 617

Filed under:
|
|

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");           
    }

© Stack Overflow or respective owner

Related posts about thread

Related posts about wpf