工人流程的想法:选项? [英] Idea for worker process : Options ?

查看:102
本文介绍了工人流程的想法:选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个代理服务,它有两个部分,它从客户端应用程序接收请求并将其放入队列中,并且有多个工作进程检查此队列,如果有任何工作要做,它将选择该部分工作和开始处理。我已将此工作程序实现为C#中的控制台应用程序。要拥有多个worker,我正在运行此控制台应用程序的多个实例。



1.使用多个控制台应用程序实例作为工作进程是否有更好的选择?

2.可以写成windows服务?如何在一个服务中创建多个工作人员?



还有其他更好的方法吗?

I am writing a broker service which has two parts one which takes request from client applications and put it in a queue and there are multiple worker processes which checks this queue and if there is any work to do it will pick that piece of work and start processing. I have implemented this worker as a console application in C#. To have multiple workers I am running multiple instances of this console application.

1. Is there a better alternative to using multiple instances of console application as worker process ?
2. Can this be written as windows service ? How do I go about creating multiple workers in one service ?

Any other better way to do this ?

推荐答案

线程可用于所有形式的C#应用​​程序 - 最简单的线程版本可能是 BackgroundWorker类 [ ^ ]



看看这里:背景工作者类初学者样本 [ ^ ]

这里: Thread vs. Backgrou ndWorker [ ^ ]
Threading is available in all forms of C# application - and the simplest version of a thread is probably the BackgroundWorker class[^]

Have a look here: BackgroundWorker Class Sample for Beginners[^]
And here: Thread vs. BackgroundWorker[^]


你的方法听起来非常糟糕。多个过程意味着相当大的开销,没有任何理由;你真的应该喜欢线程。另外,我不确定你应该有很多单独的线程;线程也应该重复使用,但我对你的目标和需要的操作知之甚少,无法提供更详细的建议。



为什么控制台应用程序不好?因为...控制台。你为什么需要它?这不是问题:您可以创建一个非控制台应用程序,根本不需要任何窗口。但是,当用户注销时,您是否需要执行该过程?如果答案是是,则需要开发Windows服务。



另请参阅我过去关于开发双模式应用程序的答案,表现为交互式应用程序或作为服务,取决于您如何托管它:使用UI配置Windows服务 [ ^ ]。



为什么这样做?调试!调试服务要困难得多,因此您可以在交互模式下调试大部分调试。这个想法怎么样?



另见我过去的答案:

使用UI配置Windows服务 [ ^ ],

Windows服务错误 [ ^ ],

http://msdn.microsoft.com/en-us/library/zt39148a.aspx [ ^ ],

如何安装windows service programmatical ly [ ^ ],

如何在用户登录系统之前启动应用程序 [ ^ ],

当我启动计算机时自动启动我的c#应用程序 [ ^ ]。



-SA
Your approach sounds awfully bad. Multiple processes means considerable overhead not justified by anything; you really should prefer threads. Also, I'm not sure you should have many separate threads; threads are also should be reused, but I know too little about your goals and required operations to advice on further detail.

Why console application is bad? Because of… console. Why would you need it? It's not a problem: you can create a non-console application, without any windows at all. But do you need the process to execute when the user logs off? If the answer is "yes", you need to develop a Windows Service.

See also my past answer on development of dual-mode applications, behaving as interactive application or as the service, depending on how you host it: Configure Windows Service with UI[^].

Why doing so? Debugging! Debugging of the service is much harder, so you can move most of the debugging in interactive mode. How about this idea?

See also my past answers:
Configure Windows Service with UI[^],
Windows services Error[^],
http://msdn.microsoft.com/en-us/library/zt39148a.aspx[^],
How to install windows service programmatically[^],
How to start the application before user login to the System[^],
Automatically start my c# application when i start my computer[^].

—SA


这篇关于工人流程的想法:选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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