Solved

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

Posted on 2010-08-15
2
1,364 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
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 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…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now