Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a library which fires events to the main window.
The library fires some events and tells when it has finished through the IsBusy property. I want the graphics to be updated by those event and particularly:

C#
private bool _isBusy;
       public bool IsBusy
       {
           get { return _isBusy; }
           set
           {
               _isBusy = value;
               if (value)
                   imgBusy.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Send,
                                             new Action(() => imgBusy.Source = new BitmapImage( new Uri(@"../../Resources/redBall.png", UriKind.Relative))));
               else
                   imgBusy.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Send,
                                             new Action(() => imgBusy.Source = new BitmapImage(new Uri(@"../../Resources/greenBall.png", UriKind.Relative))));
           }
       }


so what I expect is:

idle --> green
started ---> red
terminated ---> green

while its behaviour is:

1. when launched through backgroundworker:
idle ---> green
started --->green
midway ---> red
terminated --->green.

2. when launched without backgroundworker:
idle,started,midway,terminated --->green

But if I put a breakpoint I see that the code is hit there where the colour of the ball is changed!!

I am new with WPF in winforms there was a Mainform.Update. Is there something similar here?

Thanx for any help Patrick
Posted
Updated 10-Nov-15 5:48am
v2

1 solution

Hi,

The following link answers your question on why busy indicator does not work as expected when used without background worker and also provides a clear explanation on how to work with a busy indicator.

http://elegantcode.com/2011/10/07/extended-wpf-toolkitusing-the-busyindicator/[^]

You can also achieve the same with Tasks instead of background worker. Here is a sample:

Task taskCompare = Task.Factory.StartNew(() =>
            {
                //your long running logic or method invocation

            }).ContinueWith(compareResult =>
            {
               //do something with your result
                _busyIndicator.IsBusy = false;

            });

            BusyIndicatorContent = "your message here";
            _busyIndicator.IsBusy = true;
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900