Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
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…

911 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

17 Experts available now in Live!

Get 1:1 Help Now