C# BackgroudWorker

在很多场合下, 你需要在主(UI)线程中运行一些比较耗时间的任务,比如以下的任务

l         Image downloads

l         Web service invocations

l         File downloads and uploads (including for peer-to-peer applications)

l         Complex local computations

l         Database transactions

l         Local disk access, given its slow speed relative to memory access

这个时候UI就会陷入一种假死的状态,会给用户带来一种很不好的体验. 如何在这里发挥多线程的优势以改善用户体验? .Net2.0的System.ComponentModel.BackgroundWorker为我们提供了一个很方便的解决方法.

 

BackgroundWorker内部实现是基于delegate的异步调用.

 

backgroundWorkerDemo.zip 

posted @ 2011-11-05 20:10  跟着阿笨一起玩.NET  阅读(382)  评论(0编辑  收藏  举报