在一个Go ....中运行多个后台工作者? [英] Run Multiple Background workers in one Go....?

查看:67
本文介绍了在一个Go ....中运行多个后台工作者?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hii,

如何在一个表单中运行多个后台工作程序,以便所有工作人员以相同的速度工作...



我的prome ...?

i在一个表单中有5个后台工作者并试图以一种速度运行它们(所有这些)。

但是当我使用按钮运行所有后台工作者时面临的是什么点击事件他们一个接一个地运行,差异为3到4秒......

_______________________________



我希望所有这些都能运行一次又一次......



需要帮助



thnxxs提前

hii,
How to run multiple background worker in a single form go so that all the worker works in same speed...

my prome ...?
i have 5 backgroundworker in one form and trying to run them in one speed (all of them) .
but what m facing is when i run all the background worker using button click event they run one after another with a diffrence of 3 to 4 sec ...
_______________________________

I want all of them to run at one go and in one speed ....

need help

thnxxs in advance

推荐答案

你不能让线程以与Windows不是实时操作系统相同的速度运行。



您可以做的最好的事情是通过设置ManualResetEvent来同步所有BackgroundWorkers的开头。每个Worker开始时的代码到达MRE并等待信号开始。一旦你启动了所有的BGW,那么下一个声明应该是在MRE上设置信号,释放BGW来完成其余的工作。



即便如此,你不会有一个完美的开始。您正在与Windows中运行的所有其他线程共享CPU核心!在Windows解决之前,部分或全部线程可能根本不运行。你无能为力。
You can't make the threads run at the same speed as Windows is not a real-time operating system.

The best you can do is to synchronize the start of all of the BackgroundWorkers by setting up a ManualResetEvent. The code at the start of each Worker gets to the MRE and waits for the signal to start. Once you start all of your BGW's, then next statement should be setting the signal on the MRE, releasing the BGW's to do the rest of their work.

Even then, you're not going to get a perfect start. You're sharing the CPU cores with all of the other threads running in Windows! Some or all of your threads may not be running at all until Windows gets around to it. There is nothing you can do about this.


这篇关于在一个Go ....中运行多个后台工作者?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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