【发布时间】:2011-10-07 14:27:03
【问题描述】:
是否有库/框架可以在 .NET 中执行长时间运行的操作?寻找这样的东西:
private void button1_Click(...)
{
LongActionRunner.Execute((ref int total, ref int done) => {
// i know it's not thread-safe
total = 100;
for(var i = 0; i <= 100; ++i) {
done = i;
Thread.Sleep(100); // slow
}
});
}
当Execute() 被调用时,我需要显示一个带有进度条的窗口。如果我的操作抛出,它应该显示错误消息等。
有没有现成的解决方案?
【问题讨论】:
标签: .net winforms multithreading concurrency