简体   繁体   English

在服务器上的后台进程中运行进程

[英]Running a process in background process on the server

Hi I have a website that I need to work on. 嗨,我有一个我需要工作的网站。 Where once a process is started by the user it needs to run until certain conditions are met from live temperature data. 用户一旦启动过程,就需要运行该过程,直到实时温度数据满足某些条件为止。 It could take days before the process is completed. 该过程可能需要几天才能完成。 So once process is started it needs to run continuously on the server. 因此,一旦启动进程,它就需要在服务器上连续运行。 I have no idea how to go about it. 我不知道该怎么做。 I read about background worker processes but I am not sure if I am on right track. 我读到了有关后台工作人员流程的信息,但是我不确定自己是否步入正轨。 I want to accomplish this using asp.net and C# if possible. 如果可能,我想使用asp.net和C#完成此操作。 Can anyone put me on right track? 谁能让我走上正确的轨道? Thanks 谢谢

ASP.NET is not a good choice for implementing such long running background workers, because the worker process is recycled once in a while to minimize the effect of memory leaks (depends on the configuration, might be very often). ASP.NET对于实现这种长时间运行的后台工作程序不是一个很好的选择,因为工作程序进程会不时地回收以最大程度地减少内存泄漏的影响(取决于配置,可能经常出现)。
However, you can implement a Windows Service that runs on the server and is independent of the web application. 但是,您可以实现Windows服务 ,该服务在服务器上运行并且独立于Web应用程序。 The web application and the Windows Service can communicate through WCF (or the database) for instance. 例如,Web应用程序和Windows服务可以通过WCF(或数据库)进行通信。
Of course, installing a service on a web server might be prohibited for security reasons, so you should check this before. 当然,出于安全原因,可能会禁止在Web服务器上安装服务,因此,您应在进行此操作之前进行检查。
An alternative that is more lightweight in comparison to a Windows Service is to create a Console application and run it periodically through a scheduler, if that also meets your requirements. 与Windows Service相比,另一种更轻便的方法是创建一个控制台应用程序,并通过调度程序定期运行它(如果它也满足您的要求)。

Make windows service for running the background processes and doing the dirty work. 使Windows服务运行后台进程并完成肮脏的工作。 IIS can get restarted/app pool recycled and that will prevent your task from completing. IIS可以重新启动/回收应用程序池,这将阻止您的任务完成。 When user start process in web (UI part) use interprocess communication (tcp or named pipes) to tell the windows service about it. 当用户在Web(UI部分)中启动进程时,请使用进程间通信(tcp或命名管道)将其告知Windows服务。

you can use Threads: http://msdn.microsoft.com/fr-fr/library/ms173178%28v=vs.90%29.aspx 您可以使用线程: http : //msdn.microsoft.com/fr-fr/library/ms173178%28v=vs.90%29.aspx

They are made to treat several operations in the same time. 使它们可以同时处理多个操作。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM