Solved

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

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

735 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