user34537
user34537

Reputation:

How do i make a forever running service in asp.net?

From my other question i learned that asp.net kills my threads because 'it feels like it'. These threads are my daemons that handle thumbnail generation, registration emails and other things.

I was told to use a 'Windows Service' but what i know of, its an app you install on your machine that runs on bootup. There are several problems with using that if thats what he meant. The last time i attempted a service i remember it prove difficult and i just put the app in the startup files. anyways I AM NOT ON WINDOWS. I am on linux.

The other problems having it in a separate app is i have much code in asp.net that would need to be copied over which i dont want to do. The other is i have asp.net poke the thread using ManualResetEvent whenever it needs it so i am not hammering the db and get immediate results. AFAIK i dont know of any way to poke another process.

How might i run this code? with asp.net? I dont think checking if the threads exist every request is a good idea. What can i do?

Upvotes: 1

Views: 472

Answers (2)

Paul Turner
Paul Turner

Reputation: 39625

ASP.NET is designed to follow a request-response pattern. It has mechanisms specifically to prevent leaving threads running outside of a request, such as killing long-running threads (which it considers "broken").

What you are asking to do is not the intended function of ASP.NET. To do what you want in ASP.NET, you will be fighting the platform, not building on it. This is why you've been told to write another application which performs your long-running processes. If you're on Linux, that means writing a deamon that can host the threads you want to run continuously in the background, because that's specifically their purpose.

You must use the right tool for the job.

Upvotes: 3

Kimtho6
Kimtho6

Reputation: 6184

Take a look at this post: How to migrate a .NET Windows Service application to Linux using mono? I hope it gets you in the right direction :)

Upvotes: 1

Related Questions