views:

309

answers:

3

Hi all,

Let's say I have a situation in Silverlight where there is a background thread (guaranteed to NOT be the UI thread) doing some work and it needs to create a new thread. Something like this:

//running in a background thread
Thread t = new Thread(new ThreadStart(delegate{});
t.Start();

Lets also say that the UI thread at this particular time is just hanging around doing nothing.

Keeping in mind that I am not that knowledgeable about the Silverlight threading model, is there any danger of the new Thread() call giving me the UI thread?

The motivation or what I am trying to achieve is not important - I do not want modification to the existing code. I just want to know if there is a possibility of getting the UI thread back unexpectedly.

Cheers

+1  A: 

No, it's not possible. new Thread() is going to be a new thread, regardless of what any other threads are doing.

Dean Harding
Sounds good so far, that's what I was hoping, the reason I ask is that someone on my team thinks threads are reused
Darko Z
A: 

Good Info, including getting something back to the UI thread, here

BigChrisDiD
Thanks for your input, but that article only describes how to use Threads and why they're good to use which is not really what I'm asking about...
Darko Z
It does demonstrate creation of a new thread (3 in fact) not in any way being the UI thread. For your additional peace of mind.
BigChrisDiD
+1  A: 

OK, So I guess the question may come down to whether it is ever possible for the Silverlight UI thread to be in the thread pool that threads are allocated from when I call "new Thread()".

I have done a fair bit of searching but can't find a definitive answer on how Silverlight threading actually works. (A fair number of opinions exist but they do not always seem to agree).
It would however appear that silverlight is using a thread pool, so calling “new Thread()” may not always create a new thread (you could be allocated an existing one from the pool) depending on how the pool is managed/aged etc.

From some of the blogs I have seen the threading may even be dependant on the browser that the silverlight app is hosted in?

Drew