WPF BackGroundWorker ProgressChanged not updating textblock

Posted by user354469 on Stack Overflow See other posts from Stack Overflow or by user354469
Published on 2010-05-31T09:57:58Z Indexed on 2010/05/31 10:03 UTC
Read the original article Hit count: 279

Filed under:
|

I have the method below that seems to behaving strangely. The ProgressChanged and RunWorkerCompleted seem to be updating themselves at the same time. If I comment out the RunWorkerCompleted code which updates the Textblock I see the ProgressChanged taking effect after the data is transferred. What am i doing wrong here? I obviously want the textblock to show I'm getting data, then change when I have finished getting the data.

public void GetAppointmentsBackground() {

        System.Windows.Threading.Dispatcher webServiceDispatcher = this.Dispatcher;
        worker = new BackgroundWorker();
        worker.WorkerReportsProgress = true;
        worker.DoWork += delegate(object sender, DoWorkEventArgs args)
        {
            GetAppointmentsForDayDelegate getAppt = new GetAppointmentsForDayDelegate(GetAppointmentsForDay);
            webServiceDispatcher.BeginInvoke(getAppt);
          (sender as BackgroundWorker).ReportProgress(25);
        };

        worker.ProgressChanged += delegate(object s, ProgressChangedEventArgs args)
        {
            txtMessages.Text = "Contacting Server";
        };

        worker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args)
        {
           txtMessages.Text = "Completed Successfully";
        };

        worker.RunWorkerAsync();
    }

© Stack Overflow or respective owner

Related posts about wpf

Related posts about backgroundworker