开发者

Silverlight 4RC threading - can a new Thread return the UI Thread

Let's say I have a situation in Silverlight where there is a background开发者_StackOverflow 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


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


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?


No, even though silverlight UI thread is idle, there is message loop running on that thread waiting for UI events. So UI thread is always running and will never be returned by thread pool.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜