[英]Windows Service Application to perform long-running task only once and stop itself after completion
I am developing a Windows Service Application for sending bulk emails to the customers. 我正在开发Windows服务应用程序,用于向客户发送批量电子邮件。 In my case, I need to manually start and stop the service from the ASP.Net MVC web application passing some parameters.
就我而言,我需要通过一些参数从ASP.Net MVC Web应用程序手动启动和停止服务。 Since this is on demand and there is no schedule for this activity, I want the service to perform a long-running task (Sending bulk emails to 100K customers) only once, once started and then stop itself once completed.
由于这是按需提供的,而且没有此活动的时间表,因此我希望该服务仅执行一次长期任务(向10万个客户发送批量电子邮件),一旦启动,然后在完成后自行停止。
Thank You, 谢谢,
This approach is incorrect. 这种方法是不正确的。 A "Windows Service" is a kind of application that waits for some client to call it, or an event to happen.
“ Windows服务”是一种等待某些客户端调用它或事件发生的应用程序。 (It is called daemon in Unix/Linux jargon)
(在Unix / Linux术语中称为守护程序)
In your case, "the service" should be an ordinary program that does batch processing. 在您的情况下,“服务”应该是执行批处理的普通程序。 So, just start a separate process with Process.Start().
因此,只需使用Process.Start()启动一个单独的进程。 It doesn't block anything in your ASP.NET MVC application, it just does its job and terminate.
它不会阻止ASP.NET MVC应用程序中的任何内容,它只会执行其工作并终止。
There are two ways to track the progress. 有两种跟踪进度的方法。 You can call Process objects methods like WaitFor() with a timeout to see if it completes its job.
您可以使用超时调用诸如WaitFor()之类的Process对象方法,以查看其是否完成了工作。 Also, your "service" application would probably write its progress into a file, and the MVC application can read it anytime to see what's happening.
同样,您的“服务”应用程序可能会将其进度写入文件中,而MVC应用程序可以随时读取它以查看发生了什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.