WPF BackGroundWorker ProgressChanged not updating textblock
- by user354469
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();
    }