开发者

How to get a stable, snappy UI using threads?

I recently watching this video on 开发者_高级运维Google Chrome with great interest. It explains that Google Chrome uses one thread for IO, one for opening files and one for intermodule communication.

I think I may be able to use something similar for my own - currently quite messy - application.

I wondered if there were any good articles on best-practices or patterns for such threaded divisions of tasks?


Any time your application has tasks that can be divided into distinct groups, it's a candidate for multi-threading. Be warned that it's a dangerous game, though - for every article you can find about the advantages, there are two about getting bitten by a multi-threading implementation - it can create bugs that only occur in certain configurations (on the users computers), or worse, can't be duplicated in the debugger because the act of slowing down execution is enough to cause the bug to fail to appear (race conditions are notorious for this behavior).

That warning aside, multi-threading can be a huge boost to both the actual and the perceived performance of your application. These are .NET specific, but give a general primer explaining the advantages of background threads and keeping your UI responsive:

  • http://msdn.microsoft.com/en-us/magazine/cc300429.aspx
  • http://www.businessanyplace.net/?p=threads


If you're using .NET, the ThreadPool class is a good starting point that manages some (but not all) of the subtleties of multi-threading for you.

See also the Threads and Threading topic on MSDN for a discussion of the pros and cons.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜