Skip to main content
Home Forums General Silverlight Getting Started multi threading
6 replies. Latest Post by mexican on November 4, 2009.
(0)
mexican
Member
164 points
713 Posts
11-04-2009 5:05 AM |
Hi,
I am looking at understanding multi threading and I am not sure what method to use in SL 3.
I want the backgroundworker and dont want the UI thread . I believe you need to specify which you want.
http://www.silverlight.net/learn/videos/all/using-multiple-threads-with-the-backgroundworker/
or
http://msdn.microsoft.com/en-us/library/cc221403(VS.95,classic).aspx
or something else. I am after a simple example to learn on
Pravinku...
Contributor
4300 points
708 Posts
11-04-2009 5:39 AM |
Hi Mexican,
I have a simple demo of BackgroundWorker. Check if this helps you understand what you are looking for-
http://pkrd.blogspot.com/2009/05/working-with-background-worker-in.html
Thanks,
Pravin
"Please mark as answered, if this answers your question"
11-04-2009 6:18 AM |
I have this working with background thread.
What I need to know is how to run 2 threads that do this for example as i can do 1 thread in the background ok. How can i add 2 threads to do the same thing?
Dim bw As BackgroundWorker = New BackgroundWorker ... AddHandler bt1.Click, AddressOf bt1_click AddHandler bt2.Click, AddressOf bt2_click bw.WorkerReportsProgress = True bw.WorkerSupportsCancellation = True AddHandler bw.DoWork, AddressOf bw_DoWork AddHandler bw.ProgressChanged, AddressOf bw_ProgressChanged AddHandler bw.RunWorkerCompleted, AddressOf bw_RunWorkerCompleted End Sub Private Sub bt1_click(ByVal sender As Object, ByVal e As RoutedEventArgs) bw.RunWorkerAsync() End Sub Private Sub bt2_click(ByVal sender As Object, ByVal e As RoutedEventArgs) End Sub Private Sub bw_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs) For i = 1 To 10 System.Threading.Thread.Sleep(500) bw.ReportProgress(i * 10) a.X = i a.Y = i e.Result = "l" Next End Sub Private Sub bw_RunWorkerCompleted(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs) If e.Cancelled = True Then Me.tb1.Text = "Canceled!" ElseIf e.Error IsNot Nothing Then Me.tb2.Text = "Error: " & e.Error.Message Else Me.tb3.Text = "Done!" & e.Result & a.X End If End Sub Private Sub bw_ProgressChanged(ByVal sender As Object, ByVal e As ProgressChangedEventArgs) Me.tb1.Text = e.ProgressPercentage.ToString() & "%" End Sub
11-04-2009 6:37 AM |
Go through this article -
http://msdn.microsoft.com/en-us/library/6kac2kdh(VS.95).aspx
And find the example of using multiple threads here-
Let me know if this helps you out-
11-04-2009 7:09 AM |
I read the webpage and found this as well.
I checked out http://www.silverlighthack.com/post/2008/09/07/Silverlight-MultiThreading-with-a-Computational-Process-(Counting-Primes).aspx
This does a simple sync of threads and claims you need to use a wait handle. this seems outdated but i can understand it.
What is the wait handle they talk about and how can the threads be in sync better .
I ask because this is what i am after
11-04-2009 7:17 AM |
This is shown in the code from the link which you have shared. As far as I know, if your main thread is finished, and your child thread are still running, it keeps your main thread alive till the time all the threads have not finished the work. I might be wrong.
11-04-2009 7:24 AM |
how is this done is what i am asking. how do i code this?