Scheduled Events in ASP.NET? - c#

My website needs to somehow do something every few minutes.
Essentially I get projects from another website. I then call one of my web pages and update.
Currently I'm making a console app for this but I'm wondering if there is a better way.
Thanks

There are super cool, open source tool exist for creating a scheduled jobs in .NET
It called Quartz.NET.
I think currently is #1 tool for that tasks.

Use windows task scheduler to run the console app your writing at the appropriate times.

Depending on what needs to be done, there are a few options.
This can be achieved by a timer in a windows service.
Using the HttpCache expiration callback feature (not recommended, it is a hack).
Use a Sql job (assuming data is changing).
Building upon #Ph0en1x answer, there already is a Stackoverlow question on how to use Quartz.Net in ASP.Net

Related

Method/Task scheduler c#

I'm using C#.
I think thats a noob question but i'm try anyway.
I have a C# project with methods: X(),Y(),Z().
I'm looking for a task scheduler that run for me every day/every hour my methods (X(),Y(),Z()) at diffrent times.
What is the best way to do that?
Just make a console application that accepts a single parameter (think myapp.exe x) that would call respective function. Then add a number of scheduled tasks to Windows Scheduler and you'll be all set.
The easiest way is to use an existing library. Scott Hanselman had a blog on this a while back http://www.hanselman.com/blog/HowToRunBackgroundTasksInASPNET.aspx.
Note: the article mentions asp.net however the schedulers are mentioned can also be run through console or Windows apps.
I personally use the Fluent scheduler (https://github.com/fluentscheduler/FluentScheduler) which has now been updated to support .net core. It's easy to use, and if you have simple scheduling requirements probably the one I'd recommend.
If you want to run some code every hour, every day or any other clearly known period, then the best option is to create a console application and use Windows Task Scheduler to run this application.
If this period is unclear and depends on some logics or calculations, then the best option is using always-running Windows Services which will run your methods when necessary.
If your application is always run, you can try with reactive extensions:
Observable.Timer(TimeSpan.FromSeconds(5)).Subscribe(x=>X());
Check here for more infohttps://msdn.microsoft.com/en-us/library/hh242977(v=vs.103).aspx
I would make a windows service, and in the windows service you can call your methods with a timer check. (we did it so in our old company)

C# Console App - Scheduled on Azure

I have a very basic C# console app, which I would like to run in Azure, on a scheduled basis, like every day at 3am, for instance. I'm after some advice on the best way to implement this in Azure.
I should mention that I already have another, very similar app, for which I created a Cloud Service and Worker Role, which in essence, sits in a loop until 3AM, does some stuff then goes back to waiting. It struck me that I'm probably wasting money with this approach and that there must be a better way.
So, I did "some" research, and so far I've come-up with WebJobs and the Azure Scheduler Service but alas, neither of these A) make a lot of sense to me (at the moment, until I do more research) or B) appear to be very straight forward if all I want to do is run a simple console app once every 24 hours.
I guess I'm trying to shortcut my research because I don't want to go researching one specific method if it's not the best method for me.
So, what I'm trying to ask, in a VERY long-winded way, is....Given that I have a very simple C# Console App, what is the preferred method for "hosting" this in Azure so that I can run it in a scheduled fashion?
I believe that the easiest way is a Webjob on Website.
You can create a Worker Role and implement the scheduling using Quartz.NET.
Check out this link to see how to do it: "Using Quartz.Net to Schedule Jobs in Windows Azure Worker Roles"

C# automation application

I would like to create an auto email distributor application by C# for my company.
Usually, I would create a console application and set up a schedule to run this program from server task scheduler.
Is there any ways to build this kind of application other than console application? And what is the benefit of it compared to console application.
It can be done with every application type. Asp.net\Silverlight\WCF\WPF\WinForm...
Console Application is the easiest way because
It doesn't have a UI layer(or almost doesn't have...).
No configurations are required.
If you have a robust scheduling application (such as task scheduler), there is little point to rebuilding this inside your application. If the scheduling application is not sufficient for your needs, you'll need to embed that logic in your app.
Either way, a console application is fine. The latter scenario will just require more configuration (in the form of a configuration file probably). Still no need for a UI unless the config is complex.
You may write a Service. Writing a Service in .Net is too easy and straight forward and then you need to use a timer to invoke the operation on schedules.
A service will be executed in the background and can be configured to be executed as soon as the computer turns on.
Because services do not have user interface, you need to feed them with the requests using a database or a messaging system.
Windows schedule of a console application is ok.
If your schedule is continuous (every minute) you might be better off a Windows service see Here.
See this stackoverflow question for the comparison HERE

Simulating a cron job with a Task in Application Start

I'm trying to find a very easy easy way to start a simple cron job for my Web Application. What I was thinking about is starting a Task in the Application_Start event. This task will have a while loop and do some action every hour or so like a normal cron job would do.
Is this a good idea or will this give some trouble?
Some of the problems I could think of are the following:
The Task suddenly stops working or hangs. Maybe make some fail over
mechanism that would check if the task is still running and if not
restart it.
Memory leaking if the Task totally goes wrong and I have to restart
the whole application.
No control in changing the Task on the fly but this shouldn't be a
problem for the thing I want to do but for others it might be.
Does someone have any suggestions or experiences with trying this?
Although Darin says that doing cron jobs in a web application is a bad idea (and I agree with him in some way), it may be not so bad, when used wisely and for short running jobs.
Using same Quartz.NET in web application may be quite nice, I'm using in one of my projects like this
http://bugsquash.blogspot.com/2010/06/embeddable-quartznet-web-consoles.html for small jobs and it is running nice - it's easy to monitor (easier than monitoring remote windows process), may be used on shared hosting.
Doing cron jobs in a web application is a bad idea. IIS could recycle the application at any time and your job will stop. I would recommend you performing this in a separate windows service. You could take a look at Quartz.NET. Another possibility is a console application which does the job and which is scheduled within the Windows Scheduler.

Best method to call WCF services at interval

I have several WCF services and I want to execute methods in them at specific intervals.
For example, call Service1.DoSomeWork every 5 minutes and Service2.DoSomeWork every 10 minutes. I also want Windows client applications to be able to call the DoSomeWork methods at any time.
What is the best way to implement this?
I have complete control over the server so using Scheduled Tasks is possible but I wonder if using a Workflow in AppFabric is better or using a timer in the service itself?
Check out this post. I answered a question a while ago where the developer want to "Do something" at an interval in a windows service. I gave a pretty detailed code sample for scheduling activity within a Windows Service as recommended by other posted earlier in this thread.
how to make service act dynamically based on service running condition
I'm not familiar with AppFabric but if I were you, I will use the timer since your requirement sounds simple.
If I were your ,
I create a windows service in the server .
So that I can do anything at specific intervals....

Categories

Resources