当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Building and controlling a scheduled task or service from a web application

问题描述:

I'm building a web application that will need to import data from other database servers when it starts.

I would like to have this import done automatically at regular intervals. I would also like to be able to start and stop the import process from my web application.

What would be the best implementation for the import agent - a Windows Service? Something else?

网友答案:

Of what I heard this looks like a description for Microsoft Sync Framework. I have just few information about it for myself but will be pleased to see you pointed into that direction.

I'm not sure about your question because you are talking about hourly syncing. When talking web applications, there can't be a nice way to do such a task. You have to create a console app or best task would be a Windows Service Process (which are easier then it sounds)?

Sync Framework Intro
http://msdn.microsoft.com/en-us/sync/bb821992
Sync Framework Tutorial
http://alexduggleby.com/2007/12/16/sync-framework-tutorial-part-1-introduction/
Sync Framework Samples
http://archive.msdn.microsoft.com/sync

And, when I'm editing the answer with links

Nice guide to create a Windows Service (and setup) http://www.codeproject.com/KB/dotnet/simplewindowsservice.aspx
(if first time, try it on a test project before the production project)

网友答案:

If your web application needs to have this data in memory, you can use the Cache class.

Set it to expire every X hours, as you need and when it expires, re-fetch the data..

网友答案:

You could create a Windows Service that uses Quartz.Net to run the scheduled tasks.

You should not run scheduled task from your web app, since you don't have any guarantee that your web app is running. You're at IIS app pool management's mercy.

You might want to look at ASP.Net:Best way to run scheduled tasks.

网友答案:

This might be an oversimplification, but can you create a class that does all of this work using a Timer, and then in the application_start of the global.asax, create a BackgroundWorker that kicks off this process?

Your web application could then control the BackgroundWorker object, starting/stopping as necessary.

分享给朋友:
您可能感兴趣的文章:
随机阅读: