![]() A future developer or admin would find hard to maintain your app. The problem with this is that you would be splitting the logic and responsibilities of your code. I wouldn't recommend this option unless you really have performance problems. ![]() ![]() If your app uses SQL Server you can have a t-sql job that runs daily or hourly. The advantage is that a windows service is easier to control and monitor than a Scheduled tasks The performance hit will be small anyway as your service should check every minute to see if an hour has pass and is time to do its job. But this does not meet your performance requirements. In usual architecture (Web Server -> Application Server -> DB) this restful service should be in the Application Servers, far away from end user access.Īnother option is creating a Windows Service that runs all the time and check the time itself so every hour perform the job (maybe using Quartz or similar). I have a Windows scheduled task that runs a database import process every hour, but Id like users to be able to kick it off out-of-schedule by hitting a button in an ASP.net dashboard (running in IIS6 on Windows Server 2003). ![]() As possible disadvantage, you have to get sure that that uri is not accessible to end users. Similar as previous one, you should only invoke the restful uri to have your action done. This way Windows Scheduler daemon will launch it every hour and the rest of the time your app is not running.Ĭheck this Microsoft link to see how a scheduled task is created in windows.Īs suggested in answer, having a restful web service that allow you to perform this action instead of a console application would give you the advantage of having all code in your web application. Then I will have it run using Windows Scheduler in a daily basis (at 00:05) or a hourly basis if you prefer so. I would create that console application that every time is run perform the check for you. This is a hack and ASP isn't meant to run background tasks so use a windows service or WCF service when possible! I use this since it simplifies development, maintenance and installation.There are several options, but if I were you I would go with first or second options. For your specific case you could start a timer that executes tasks like this. Use a Task instead of action to benefit from cancellation options. HostingEnvironment.UnregisterObject(this) After that time span, if there are any registered objects left, it will call them again with immediate set to true.īy preventing the Stop method from returning (by locking a field when the worker is busy), we stop ASP from shutting down the AppDomain until our work is finished. ASP.NET gives all instances of IRegisteredObject a total of 30 seconds to complete their work, not 30 seconds each. This gives your code a bit of time to finish what it is doing. In most cases, it’ll call this method twice, once with immediate set to false. When ASP.NET tears down the AppDomain, it will first attempt to call Stop method on all registered objects. Job filters allow you to add custom features to the background processing in a way similar to ASP.NET MVC action filters. To do this implement the following interface: public interface IRegisteredObjectĪnd register your object to ASP using the following static method: HostingEnvironment.RegisterObject(this) A Windows service will then call the ASP.NET application at scheduled intervals. In the Begin the task dropdown select On an event. This will serve as the broker between it and the Windows service that calls the ASP.NET application into action. To set it up, create a new scheduled task, select the Triggers tab, and add a new trigger. To prevent this, you can register your background thread to ASP.Net so it will notify your thread to shut down. An ASP.NET Web service will provide you with an interface into the existing ASP.NET application that holds the task logic. Problem is, ASP.Net can recycle the AppDomain at anytime (killing my background thread). The IHostedService runs as a singleton for your task processing. When using the hosted service, you do need to keep in mind to handle the dependency injection correctly. I had a similar problem, I'm developing a ASP proof of concept and use a background thread that performs a task that could take several hours. When running a background task in ASP.NET Core, the IHostedService gives you a good skeleton to build the scheduler logic.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |