Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

856 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