如何限制并发进程的数量? [英] How to restrict number of concurrent processes?

查看:417
本文介绍了如何限制并发进程的数量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的情况如下:


  1. 我有一个应用程序只能启动固定次数(少于50次)

  2. 由于业务需求,不允许单独的中央流程来管理其他流程。

  3. 我正在使用C#开发应用程序,因此管理解决方案是首选。

  4. 我必须处理意外的情况,例如可以使用TaskManager终止进程。

  1. I have an application that can be started only a fixed number of times (less than 50).
  2. A separate central process to manage other processes is not allowed due to business requirement. (ie. if a nice solution that involves ONLY the application processes is still acceptable)
  3. I am using C# for developing the application and therefore managed solution is preferred.
  4. I have to deal with "unexpected" cases such as the processes can be terminated by using TaskManager.

的解决方案,使用系统范围的互斥。然而,它不能幸免非预期的情况下非常好的方式,它离开废弃互斥。如果这是一个好方法,我可以问什么是忽略放弃的互斥量的捕获?

I am thinking of solution that make use of system-wide mutex. However, it doesn't survive the "Unexpected" cases very well in the way that it leaves "abandoned" mutex. If this is a good way, may I ask what is the catch of "ignoring" the mutex abandoned?

推荐答案

可以查询进程列表并计数当前活动的实例数。另一种方法,更多的comples,将是广播UDP和计数响应的数量。

One approach would be to query for the process list and count the number of instances currently alive. Another approach, more comples, would be to broadcast UDP and count the number of responses. I have used this pattern for distributed scenarios related to job processors.

HTH

Colby Africa

Colby Africa

这篇关于如何限制并发进程的数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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