Solved

SilverLight 4: do I need an extra thread for BusyIndicator to work?

Posted on 2010-08-15
2
1,374 Views
Last Modified: 2013-12-17
Hi Experts:

    I am trying to write a SilverLight 4 program that if I click a button, then the BusyIndicator will show up for 3 seconds. I tried two ways of coding in the button-click event handler.

This way didn't work (the busy indicator never show up even though the program sleep for 3 seconds).
************************************************************
BusyNote.IsBusy = true;   // set busy indicator
System.Threading.Thread.Sleep(3000);
BusyNote.IsBusy = false;
************************************************************

The following way works fine (the busy indicator shows up for 3 seconds).
******************************************************************************
BusyNote.IsBusy = true;  // set busy indicator
System.Threading.ThreadPool.QueueUserWorkItem((state) =>
  { System.Threading.Thread.Sleep(3 * 1000);
  Dispatcher.BeginInvoke(() => BusyNote.IsBusy = false); }
);
*******************************************************************************

My question is:
1. if I want to let the button event handler do a time consuming job, do I always need to make/find another thread and put the actual work inside?
2. why it didn't work in the first example? is it because the busy indicator is set in the same thread of the sleeping work?

Thank you.
0
Comment
Question by:huangs3
  • 2
2 Comments
 
LVL 16

Accepted Solution

by:
CuteBug earned 500 total points
ID: 33442898
If you want the button event handler to do a time consuming job, it would be better if you utilize BackgroundWorker for that and let the Busy Indicator be on the main thread.
BackgroundWorker fires an event when its work completes.
Handle that event and stop the Busy Indicator then.
0
 
LVL 16

Assisted Solution

by:CuteBug
CuteBug earned 500 total points
ID: 33442911
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question