我有一个下载网站的函数:
let downloadPage (address : string) =
async
{
// do some magic here
}
它的类型是“字符串 -> 异步字符串”。
我想下载几个页面 - 让“pagesToDownload”成为包含所有页面的序列。然后我可以写:
pagesToDownload
|> Seq.map downloadPage
|> Async.Parallel
|> Async.RunSynchronously
这个功能可以正常运行,但是需要一些时间来完成。我计划在我的UI中使用此函数,因此提供一个ProgressBar会很好。
我找到了一篇关于在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>
实现作为参数使用。 - Patryk Ćwiek