开发者

What is the relationship between the JavaScript thread and the Silverlight UI thread?

JavaScript is single threaded - Silverlight is not, but interaction between JavaScript and Silverlight must be performed on the Silverlight UI thread.

However, what exactly is the relationship between the Silverlight UI thread and 开发者_如何学运维the JavaScript thread? Are they by any definition the same thread, or separate threads with the interactions performed purely through the respective event loops and blocking one thread when waiting for the other (when evaluating/calling JavaScript from Silverlight for example)? Put another way, can JavaScript execute concurrently with Silverlight actions on the UI thread (and can multiple Silverlight instances hosted in the same page have their UI threads running concurrently)?


I haven't used Silverlight, but I've done pretty extensive work with Java Applets and Flash, so I'll comment from that perspective.

You're right that JavaScript is single-threaded. Anything that causes it to block will prevent all other computation and actions. It will even lock the browser in some cases, though newer browsers are getting better at separating out tabs into separate processes, which helps.

Any thread in a plugin like Silverlight is completely separate from JavaScript in the browser. The interfaces between them may be blocking however. If Silverlight's UI thread blocks when communicating with native JS, then no other work will be done on that thread while it's waiting. Other threads can continue to work as normal.

To address your question about whether JS can execute concurrently while actions on the Silverlight UI thread are running, I don't see why not. They have separate runtimes, and as long as they're not intercommunicating (which would cause one to block), they should be able to keep running fine in isolation.

My gut says the same would be true of multiple Silverlight instances in the same page, but that's really an architectural design question that I'm not able to answer.

Hope this helps!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜