【发布时间】:2015-06-26 19:30:42
【问题描述】:
有没有一种方法可以用来设置 IObservable.SelectMany 的最大线程数?
以下代码非常适合在处理项目时更新 UI,但目前我尝试执行的任务有点占用资源。我想将最大线程数设置为两个,以减少资源使用量。
AsyncCommand = ReactiveCommand.CreateAsyncObservable(_ =>
{
// Set progress bar indicator to 0
var set = new [] {...} // The set of items to process
// Set the progress bar indicator max to the count of the items to process
return set
.ToObservable()
.SelectMany((item, index) => Task.Run(() =>
{
// Process item
return item;
}), (item, index, processed) => item);
});
AsyncCommand
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(item =>
{
// Step the progress bar indicator
});
【问题讨论】:
标签: c# system.reactive reactiveui