支持的进展情况,并在.NET 4.0和QUOT增量的结果;任务并行库" [英] Support of progress reporting and incremental results in .NET 4.0 "Task Parallel Library"
问题描述
我知道,任务并行库仍处于测试阶段,也有可能是更少的资源可用,但无论从那个我看了,图书馆给人很特别的待遇的任务调度</A>,异常处理和的cancellation 。
I know that Task Parallel Library is still in Beta and there are likely to be less resources available but from whatever I have read, library gives very special treatment to task scheduling, exception handling and cancellation.
但我不觉得为进度从任务报告和发送增量结果的任何引用。这两个事情似乎太重要了,不容忽视。你能否对如何在任务并行库处理这些一些轻或引用一些文章,这也解释了他们?
But I don't find any references to progress reporting and sending incremental results from tasks. These 2 things seem too important to ignore. Can you throw some light on how to handle these in Task Parallel Library or refer some articles which explains them?
推荐答案
此示例更新进度条:
using System;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
class SimpleProgressBar : Form
{
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.Run(new SimpleProgressBar());
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
int iterations = 100;
ProgressBar pb = new ProgressBar();
pb.Maximum = iterations;
pb.Dock = DockStyle.Fill;
Controls.Add(pb);
Task.ContinueWith(delegate
{
Parallel.For(0, iterations, i =>
{
Thread.SpinWait(50000000); // do work here
BeginInvoke((Action)delegate { pb.Value++; });
});
});
}
}
<一个href="http://social.msdn.microsoft.com/Forums/en-US/parallelextensions/thread/38d7a436-e1d1-4af8-8525-791ebeed9663"相对=nofollow>从内更新一个进度条的Parallel.For
这篇关于支持的进展情况,并在.NET 4.0和QUOT增量的结果;任务并行库&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!