【发布时间】:2014-07-20 21:39:34
【问题描述】:
我有一个下载网站的功能:
let downloadPage (address : string) =
async
{
// do some magic here
}
它的类型是“字符串 -> 异步字符串”。
我想下载几个页面 - 让“pagesToDownload”成为包含所有页面的序列。然后我可以写:
pagesToDownload
|> Seq.map downloadPage
|> Async.Parallel
|> Async.RunSynchronously
这工作正常,但需要一些时间才能完成。我打算在我的 UI 中使用这个功能,所以最好提供例如进度条。
我发现了一篇关于在 WPF 中使用 ProgressBar 的好文章: http://elegantcode.com/2009/07/03/wpf-multithreading-using-the-backgroundworker-and-reporting-the-progress-to-the-ui/
但我看不出如何将这两个想法结合起来。下载网站的模块是用 F# 编写的,而 UI(ViewModel 和 View)是用 C# 编写的。
【问题讨论】:
-
您可以接受
IProgress<T>,并在下载一堆页面的方法中使用默认的Progress<T>实现作为参数。
标签: wpf asynchronous mvvm f# progress-bar