Most people use DispatcherTimer in Silverlight as a way to have a multithreaded Silverlight application, yet even when DispatcherTimer gives you the way to call methods on an interval, is not multithreaded and needs to interrupt other tasks to trigger the event on the main application thread.
If you have used the Threads in .NET you’ll find Silverlight threads straightforward as the class still call Thread and the namespace is from System.Threading.
ThreadStart queueReader = new ThreadStart(QueueReader); Thread inputQueueThread = new Thread(queueReader);
The QueueReader is the method to call, so the last thing to do is to start the thread by using:
inputQueueThread.Start();
The method will start immediately and after the thread will terminate and cannot be reused. As the Thread in .NET, Silverlight has the same properties but the thread priority, all threads are set to background threads.
My personal suggestion to any developer wanting to use threads on their Silverlight applications is, try to not overuse it as you are running it on the clients CPU, do not try to interact with the thread, just do your background work and let it terminate. I would also recommend not to use Thread.Sleep as if the user closes the browser the clean up will be more than you may want to take.
Use delegates on threads, to call you on complete or on cancelled. Remember the browser will call Abort when need it. Just because Silverlight has multithreaded support, doesn't mean that you need to write all your Silverlight applications with Threads. Silverlight events are extremely powerful, I recommend to familiar yourself to those and used them wisely.
Cheers
Al
Follow me in twitter | bookmark me | Subscribe to my feed


