سؤال

I need to run a polling service in a ASP.NET-WebService. Now, I have implemented it with a BackgroundWorker which I am starting in Application_Start of the HttpApplication. This is working. But suddenly, it will not continue working anymore.

Now, I have the fallowing Question: What is the Lifetime for a HttpApplication, after it has started and executed Application_Start? Have I to implement and run my BackgroundWorker at another place?

هل كانت مفيدة؟

المحلول

BackgroundWorker is not designed for your use case. As quoted from MSDN:

The BackgroundWorker class allows you to run an operation on a separate, dedicated thread.

Normally asp.net app pool is configured (default IIS setting) to shut down after 20 minutes of idle time. Which is what I think is happening in your case.

You should develop a Windows Service. Following is brief about the same:

Windows services enable you to create long-running executable applications that run in their own Windows sessions. These services can be automatically started when the computer boots, can be paused and restarted, and do not show any user interface. These features make services ideal for use on a server or whenever you need long-running functionality that does not interfere with other users who are working on the same computer.

You can reuse all of your existing code. Just call you web service periodically from this windows service as per your requirement. That's it.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top