并行foreach循环检查状态 [英] Checking status of parallel foreach loop

查看:221
本文介绍了并行foreach循环检查状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相当长的平行foreach循环我需要运行。 100多台计算机网络上的将被访问,每个计算机上的每个操作将需要几秒钟。并行foreach循环似乎是为这个完美的解决方案,以加快这一进程。

I have a fairly long parallel foreach loop I need to run. Over 100 computers on the network will be accessed and each operation on each computer will take a few seconds. Parallel foreach loops seem like the perfect solution for this to speed up the process.

你是什么视觉线索能够拿出这将很容易让用户看到环路的进展如何?很明显,因为它是辑阵线程更新GUI是昂贵的,有风险的,所以我的问题是什么其他的视觉指标可以用来显示进度?

What visual clues have you been able to come up with that will make it easy for the user to see the progress of the loop? Obviously because it is mutli-threaded updating the GUI is expensive and risky, so my question is what other Visual indicators can be used to show progress?

推荐答案

那么你不应该直接更新从后台code中的UI线程,但你一定可以考虑更新一些共享一块内存到沟通进展情况。

作为一个非常简单的例子,如果你的code可以被视为一系列重复的步骤,你可以增加一个计数器。该 Interlocked.Increment() 的方法是一种用于此目的特别有帮助的,因为它这样做而不需要锁定。那么你的UI线程会定期轮询此计数器并报告它的价值 - 或者,如果可能的想象它(如可能是一个进度条或移动平均值)

As a really simple example, if your code can be treated as a series of repeated steps, you can just increment a counter. The Interlocked.Increment() method is particularly helpful for this purpose, as it does so without requiring a lock. Your UI thread could then periodically poll this counter and report it's value - or visualize it if possible (as perhaps a progress bar or running average).

如果多台机器都有涉及,它可能是有意义的继续就如何整体任务进度所有参与同行每台机器和报告的计数器。你也可以考虑可视化完成的步骤之间的平均运行时间...这可能有助于该系统的用户估计完成时间(你也许可以计算出这个问题,以及)。

If multiple machines are involved, it may make sense to keep a counter per machine and report on how the overall task is progressing across participating peers. You could also consider visualizing the average elapsed time between completed steps ... which may help users of the system estimate the time to completion (and you could perhaps compute this as well).

更复杂的实现也是可能的。可以,例如,创建共享队列向其发布记录信息或每个活动状态。这可以得到pretty的复杂......如果执行不力可能会对性能产生负面影响。

More complex implementation are also possible. You could, for instance, creating a shared queue to which you post logging information or per-activity statuses. This can get pretty complicated ... and if implemented poorly could have an adverse affect on performance.

另外,如果你想收集显著多项性能指标有关分布式处理,你可以考虑使用的性能计数器API System.Diagnostics程序的。这是一个比较复杂的路径 - 但它允许您利用在操作系统的高性能指标收集和发布实施,并允许您查看和使用类似的性能监视器

Alternatively, if you want to collect a significant number of performance metrics about your distributed process, you could consider using the Performance Counters API in System.Diagnostics. This is a more complicated path - but it allows you to leverage the high-performance metric collection and publishing implementation in the OS and allows you to observe and aggregate performance information using a tool like Perfmon.

您使用更新UI的具体机制,依靠什么技术你正在使用(WPF中,的WinForms,HTML)和分布式code和UI code之间是否有共同位于一个单独的任何部件处理。如果分布式/ UI部分在一个单一的过程中没有被托管,您可能需要使用某种形式的IPC通信和可视化的进展。

The specific mechanisms you use to update the UI depend on what technology you are using (WPF, WinForms, HTML) and whether the distributed code and the UI code have any components co-located within a single process. If the distributed/UI portions are not hosted within a single process, you will likely need to use some form of IPC to communicate and visualize progress.

这篇关于并行foreach循环检查状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆