0

I have a web application that do some work on database every specific time, so how can I keep it doing its work even I close the web browser?

Is using a Thread useful and will it work for me? What other available solutions?

5
  • 3
    Do not use your web application for long-running tasks. That's not what they are meant for. Instead, use a Windows Service or Scheduled Task to perform long-running or periodic operations. Leave the web application for request/response work. Commented May 8, 2015 at 11:21
  • The application isn't stored locally , it is stored on a hosting space , so i can't use a windows service . Commented May 8, 2015 at 11:23
  • @AhmadShaheen There is a way to do something similar - blog.stephencleary.com/2014/06/fire-and-forget-on-asp-net.html, but it is obviously not recommend. Commented May 8, 2015 at 11:38
  • @EugenePodskal: The HostingEnvironment.QueueBackgroundWorkItem can be considered 'advised' in my opinion. Added it to my post. Commented May 8, 2015 at 11:44
  • Also look at Quartz.Net for running tasks at a specific time.quartz-scheduler.net Commented May 8, 2015 at 12:51

1 Answer 1

7

You don't want to do that. A regular web server process isn't a background worker that runs forever, it replies on requests and it keeps some state. You don't want to let your thread end because of the application pool getting recycled, sessions time out, etc.

You have a few options, which you could use:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.