I am trying to develop an application that will scan a website, get data from the website and save that data into database 3x per day at given hour that can be set in xml configuration file.
As an addition group of users can trigger the start of the application manually max few times per day.
I am looking for pros and cons of using a windows service for this solution or should I set a 3 scheduled tasks that will run the console application?
If I will decide to use a windows service then what is the best way to trigger a manual start of the service while the service is already running? The group of users will have some kind of web interface to trigger manual start.
This could be easily done using a scheduled task. I would just set a 3x scheduled tasks that will run the application at given time and the group of users could just start the .exe file from the web interface. However how to only allow the user to run a manual trigger only if application is not already running?
Since the UI is ultimately in web, and thus the service itself won't need any UI, I would go with Windows service which can be triggered to start by the user through web or automatically as the time comes (by its internal code).
Then, either:
In the service it has something to indicate its status as running which can be captured by the web app to see it, or,
In the web, there is mechanism to request/monitor the service status
Is quite flexible I think. I would go with whichever is easier.
I picked the task scheduler option for my case. It was easier to implement the manual triggering by users mechanism.
Pros - Triggers can be added easly using the taks scheduler library.
Related
I have a classified web application developed with ASP.NET MVC and I need to implement a advert bump up option.
As a example if someone use this option (for 3 days) today at 10.15 AM, advert should bump up each day 10.15 AM for 3 days.
So I need a scheduler to execute some code to bring up the advert to top of the list.
Can someone explain me how approach this inside my ASP.NET MVC application or using any other 3rd party resource?
save on the database every time the user click on the option. and every time he clicks on the option check if he has click in the pass two days.
You will need to use a task scheduler service. It is not possible to create a scheduled task in ASP.NET MVC, because it simply listens and responds to HTTP requests. You could put your code to bump up the advert in an ASP.NET MVC controller, but you would still need something to send an HTTP request to trigger the controller at the given time. So there's probably not a great reason to put that code in a controller under most circumstances.
It is easy to set up scheduled tasks in most cloud computing environments. For example, in AWS you could write a Lambda function in C# and schedule it with a CloudWatch Events rule.
If your application is running on a Windows Server, the most robust way to implement a task scheduler would probably be to write a Windows Service application to call the task logic on a polling loop. It is also possible to create a console application and trigger it with the Windows Task Scheduler. This approach is quicker and easier to get up and running than developing a Windows service, but in my experience is more likely to fail and quit running without your knowledge. Either way, it will be important to make sure to write good logging and error notification code.
I'm sure there are also good 3rd party tasks schedulers out there too, I just haven't used any of them. Those are just some general guidelines, but if you want more detail on them just let me know and I can post some links.
I need to create an application that will run on a server and be able to be configured to run commands at certain times. For instance, there will be a web interface allowing a user to set an engage time and a disengage time. Once those values have been saved by the user I need for the server to be able to fire off those commands precisely at the time specified each day.
I would also need to be able to set single use non recurring events that would occur... maybe 10 minutes from the time an event was triggered and have a command fired off when that 10 minute timer goes off.
I've already got a class library written that has the engage and disengage commands exposed. I would hope to be able to integrate this into whatever solution I end up with and simply be able to make calls directly to the class. Alternatively I could also compile the class library into an executable and have commands issued to it via command line. I'm hoping to not have to do the latter.
I've never written anything like this before. I've peeked a bit at Windows Services, but there is a lot of chatter out there saying that it isn't necessarily the best option. Can someone please guide me in the right direction please?
A windows service is not a bad idea, its perfect for this kind of application. Unless you end up using standard windows scheduled tasks as the trigger for your command, you need some sort of process that is always running to contain your scheduler. A windows service is an excellent candidate for this.
Using a windows service in conjunction with Quartz.NET and some sort of persistence layer so you can store your schedules (in case you need to restart the service or it crashes etc) would be a good way to go.
Alternatively, you could write an application that just adds and removes windows scheduled tasks, but considering you have existing class libraries, using Quartz.NET will fit in well with your existing libraries.
easiest solution:
make a console exe and run under scheduled task in windows.
Let web page to accept user input and modify a configuration file.
So this is my first stint with programmatically creating windows service or scheduled tasks and I am confused which one to choose. I had a look at various articles like http://weblogs.asp.net/jgalloway/archive/2005/10/24/428303.aspx , scheduled task or windows service and some more but can' t really decide btween the two
Here is my scenario :
My application will pick up the code paths of a few dlls from the db , execute the DLLs using MSTest.exe and log back the results to the Db. this will probably be repeated every 2-3 hours . Now I am leaning a bit towards scheduled tasks since i won't have to worry about memory related issues but need some expert advice on this.
P.S. : The DLLs contain test methods that make calls to web services of applications deployed on various servers
Thanks in advance for the help
A Scheduled Task would be more appropiate for your scenario. I don't think it make a lot of sense building a scheduling mechanism on a windows service when OS already provides scheduling infraestructure.
A Windows service is more appropiate for processes that have to respond to events at any moment and not at specific and fix periods. That's why they are running all the time. An example of this is the SQL Server Service.
An exception of this could be a task that needs to run every second or so. In that corner case, a Window Service could be the best solution. For your specific schedule, I have no doubts that a scheduled task would fit much more better.
Although this post is several months old, here's a possible resolution in case it's helpful to others for the "Run whether the user is logged on or not" issue : start with a console project then change type to Windows App as mentioned at Run code once and exit formless app: Windows Forms or WPF... does it matter?:
“If you never show a UI, you should start with a WinForms project (WPF projects set extra project metadata that you don't want), then delete the reference to System.Windows.Forms.dll. Alternatively, start with a console project, then change the Output type to Windows Application.”
I have a clockIn & clockOut module that records start time & end time for workers from an Asp.NET app.
I want to ask how to do cron job for asp.net application to see if a worker has not entered their time on that date or week and send an email notification to remind them to enter start time and end time.
ASP.NET is the wrong tool for the job. You would be better off either writing a Console Application that is run on a scheduled task, or a Windows Service that polls on a regular interval. ASP.NET is purely meant for a request/response model.
Either one can access whatever data store the website is reading from/writing to just as easily as the ASP.NET site can.
If you've done neither, the Console Application is by far the simplest to write and implement. Windows Services aren't all that bad, but involve extra overhead, including difficulty debugging, and the need to go through a special installation process as compared to the XCOPY deployment model possible with Console applications.
If you REALLY want to do it in ASP.NET, you can write an asp.net web page that does this, and use the Windows Scheduled Task to run it. The Scheduled Task can open up Internet Explorer to a specific page just as easily as it can run any executable. But I wouldn't recommend it. You'll forever have to close the IE window when the task is finished, and it's just really a "hackish" solution. I did it back when I was a pure web developer and didn't know any better, but not since.
Jeff Atwood posted on the Stack Overflow blog, titled as Easy Background Tasks in ASP.NET, in the early days of this site about a simple way to do background tasks in ASP.NET. If your tasks are relatively lightweight, this might not be a bad way. If you have a reason to really want to keep everything inside an existing ASP.NET app, this might be the way to go.
The gist:
At startup, add an item to the HttpRuntime.Cache with a fixed expiration.
When cache item expires, do your work, such as WebRequest or what have you.
Re-add the item to the cache with a fixed expiration.
Although its not technically a cron job, from within a website you can get the website to call a set page at X time of the day.
I have done this a few times via a web method call, which is called on the timer from the application start.
Basic explanation is here:
Call a webpage from c# in code
I have a project that get daily securities end of day values from the web and store them in a database.
I want it to happen once a day at a specific hour.
What is the best approach for that kind of need?
The simplest way:
Create a console app to perform the task and use the Windows task scheduler to run it at the desired time and interval.
You could also create a Windows Service but these are harder to deploy and debug than a console app.
(easiest first)
Schedule your application using Windows Scheduler
Implement a Windows Service and use Quartz .NET for scheduling
Implement scheduling manually and just keep your application running forever
You have a LOT of options, all with pros and cons. Just to name a few :
A loop that would keep your application running in the background.
A schedule agent that would launch your application once a day.
Using Windows Scheduler.
Another third party (or your own) scheduling application.
Given so little information, anything I'd be telling you about which is best for you wouldn't be worth a byte!
Option1: You can do it in your Csharp code using the date time check inside a timer control that triggers on regular interval. This approach is bad since it requires your application running continuously.
Option2: You can use a scheduled task in your OS and run the application at the specific hour to attain the same. My company follows this to generate automatic reports
Option3: You can use a windows service.(A Simple window service tutorial)
Here is a link that will help you decide whether to choose a scheduled task or a windows service.
Check out this post http://www.codeproject.com/KB/cs/Midnight_Timer.aspx and change it from midnight to the time you require.