简体   繁体   English

如何将所有请求从客户端发送到服务器中的单个进程?

[英]How can send all request from client to single process in server.?

I am developing the web site, It consists of device name list and related Build Button. 我正在开发网站,它由设备名称列表和相关的“生成”按钮组成。 When one click the Build button the one process will run in server. 当单击“生成”按钮时,一个进程将在服务器中运行。 When more than ten user click the Build button more processes will create at that server will hang. 当十多个用户单击“生成”按钮时,将在该服务器上挂起的更多进程将挂起。 How can send all request from client to single process in server. 如何将所有请求从客户端发送到服务器中的单个进程。

You could set up a WCF Windows service that internally has some kind of count of currently running processes and makes sure that there are never more than X threads each running one process. 您可以设置一个WCF Windows服务,该服务在内部对当前正在运行的进程进行某种计数,并确保每个运行一个进程的X线程数量不得超过X个。 If you want exactly one, rather than just a limited amount, you don't even need to worry about the threads and can just halt other requests while it's processing one. 如果您只需要一个请求,而不是有限的请求,您甚至不必担心线程,可以在处理一个请求时暂停其他请求。

It might make it more difficult to give feedback to the users though if that's needed, since if one or more processes are queued, you can't immediately tell the user that the build has begun etc. 如果需要的话,向用户提供反馈可能会更加困难,因为如果一个或多个进程排队,则您无法立即告诉用户构建已经开始,等等。

It sounds like you are spawning a process thread to do the build on the sever (I don't recommend this, as spawning threads in a ASP.Net application can be tricky ). 听起来您好像正在生成一个进程线程以在服务器上进行构建(我不建议这样做,因为在ASP.Net应用程序中生成线程可能很棘手 )。 The easiest way to get around each request spawning a new thread would be to separate out your build process from the Asp.net web application. 解决每个请求产生新线程的最简单方法是将构建过程与Asp.net Web应用程序分开。 So: 所以:

  1. Move the build action to a Windows Service on the same machine. 将生成操作移至同一台计算机上的Windows服务
  2. Use Windows Communication Foundation to expose the service entry point to the Asp.Net application 使用Windows Communication Foundation将服务入口点公开给Asp.Net应用程序
  3. Make the WCF instance a singleton instance , so that only one request can access it at a time. 使WCF实例成为单例实例 ,以便一次只能有一个请求可以访问它。 (This is the drawback of using only one thread.) (这是仅使用一个线程的缺点。)

Your other option is to log the requests to a queue, and have a process (windows service maybe) monitor the queue, and process it one at a time. 您的另一种选择是将请求记录到队列中,并有一个进程(可能是Windows服务)监视队列,并一次处理一个。 The drawback to this is that you won't get immediate results for the user. 这样做的缺点是您不会立即为用户得到结果。 You'll need some way of notifying them when the process has finished, but you'll most likely have to do the same thing with the above solution too. 您将需要某种方法在流程结束时通知他们,但是您很可能也必须对上述解决方案做同样的事情。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用单个 TcpClient 实例将多个字符串消息从客户端发送到服务器? - How can I send multiple string messages from client to server using a single instance of TcpClient? 为什么客户端(C# 的 HoloLens)无法从服务器(python 的 PC)接收消息? (客户端可以向服务器发送图像。) - Why the client (HoloLens by C#) cannnot receive message form the server (PC by python)? ( The client can send images to the server.) 从服务器发送请求到WPF客户端应用程序 - send request from server to wpf client application 如何使用端口从服务器向客户端发送消息? - How I can send message from server to client using the port? 如何在不发送客户端请求的情况下从Windows Azure服务器向客户端移动应用(iOS)发送消息? - How to send a message from a windows azure server to a client mobile app(iOS) without the client sending any request? 套接字单个客户端/服务器连接,服务器可以发送多次,客户端只能发送一次 - Socket single client/server connection, server can send multiple times, client can only once 仅SignalR客户端调用从服务器获取更新。 MVC - SignalR only client calling is getting the update from server. MVC 如何在服务器广播中使用 signalr 仅对单个客户端,而不是所有客户端? - How can I use signalr in server broadcast to a single client only, not all clients? 如何将对象从客户端发送到服务器并反向发送? - How to send an object from client to server and reverse? 如何从服务器读取数据并将其发送到客户端? - How to read and send data to client from server?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM