I am developing an email marketing WinForm application. And for the scheduling of campaigns, I decided to use Quartz.NET. I need it to be running as a Windows Service. but I also want the user to be able to add a job (e.g. a campaign that needs to be run everyday at 8 AM which is basically running a .bat file) to the service through the program.
I am also saving all the job schedules in the database so that when you stop/start the OS or Windows Service it can still read from all the jobs that need to be run.
How can I add a job to the service while the service is running? The dynamic addition/removal of the job to the service is of course much preferred. Stopping the service and reading all the jobs again from the database is, to be frank, my last resort.
You can install Quartz.Net as a windows service and configure it to use AdoJobStore.
Your WinForm application will be the interface where you can add, suspend and remove jobs and triggers.
You do not have to stop your windows services while you're doing that.
You do not need to read your database to figure out what's happening in Quartz but you must use the APIs provided.
I've done something similar long time ago; my quartz.net "manager" was a web application.
You can read my answer here.
I guess the steps to do what you're looking for a pretty much the same.
Reference to Quartz.net samples and a free book can be found here and here.
Related
We have 20+ console applications for background processing(sending emails, tagging customers based on condition etc). Currently, all are configured using a windows task scheduler and hosted on a different server. it's difficult to manage and schedule manually.
I am new to microservice architecture.
can I create and run all this jobs with MS architecture.
This can be done via programatically and configuration option. Basically save the schedule configuration and apply on application. you may have to design User interface or xml file based configuration to save the schedule details for each job. In java, Quartz framework is quite popular. For .Net - refer Quartz.Net Cron expression
To create a background process or schedule jobs you can do it in your .Net application or via the Windows Service application.
To do it in your .Net Application you can do it with Quartz or HangFire. Both are reliable and straightforward.
To do it in a Microservice environment you can create an independent service and add your new jobs to it.
Also, even you can listen to events inside this specific service and fire it whenever each service wants. It would be quite flexible
Another option is that you can use Worker Services in. NET which helps you to create and run your specific instance of your application (Thanks to dotnet core).
If you ask me which one is the simple one I would ask Quartz.
I am planning to create a service that checks something on a website with an interval. Compares the results with the DB and sends a email out if changes has been made.
No user interface is needed.
What type of service should I use for this type of application?
There's no single correct answer to your question. If you want to keep things really lightweight, you could use an Azure Function App with a timer trigger.
If the Function App model isn't right for you, you can deploy a scheduled Web Job to an App Service deployment.
For some scenarios, the best alternative is a virtual machine with cron / Windows Task Scheduler. For others, it's to write an app that comes with its own scheduler.
You can try to look at Azure Functions. That is probably the simplest thing you can do and it can run on timer. That seems quite relevant to your use case.
Azure Functions supports an event based on a
timer using Cron job syntax. For example, execute code that runs every
15 minutes and clean up a database table based on customised business
logic.
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?
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 Best way to run scheduled tasks.
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)
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.
I want to schedule my windows service with Quartz.NET.I tried some examples but,i can't schedule my windows service.How can i do it?
Thanks.
Well, you're not actually "scheduling" your windows service. The Quartz.Net server can run as a windows service and then look at your quartz_jobs.xml to determine the time/frequency (or whatever you have setup as a trigger) to fire your jobs you have defined.
Check out this blog post series for more info - http://jvilalta.blogspot.com/2009/03/getting-started-with-quartznet-part-1.html
It was helpful for me to get started versus the tutorials on the Quartz.Net site.
It's work for me :
"A quick way to create a windows service using Autofac, Quartz and Atlas"
http://www.markjourdan.name/a-quick-way-to-create-a-windows-service-using-autofac-quartz-and-atlas
I want to develop an Online Reminder service in ASP.NET 2.0 (C#) and SQL2005. But I am not getting the concept of reminder service. What I know is using an online reminder service I can schedule a reminder for future dates, which is sent to me (who schedule reminder) via email or SMS on that date. But in asp.net how to do this, caz anyone can schedule a reminder for any date, how we'll know that when to send that mail to the person. We have to put some loop or what.
So please guide me, what is the concept of an online reminder service and how I can easily develop this application using ASP.NET and SQL
Edited
I am on Shared hosting server, so that solution must be able to work on shared hosting.
Or
Please tell me if anyone knows about any FREE and open-source reminder service CMS which I can download and study it.
Microsoft SQL Server 2005 have scheduling (sql jobs) and email features. You may even donot need to use ASP.NET.
Ideally, you would have a windows service that would periodically (every few minutes) check if any new reminders need to be sent out. Since you are on shared hosting, you probably can't install a service though.
I'm not very familiar with windows shared hosting, but if you have the option of creating scheduled/cron job type tasks you could probably do it that way.
If you can't create a scheduled task on your server, another option would be to create a scheduled task on your home PC with a program/script that runs every few minutes and simply hits a special web page on your site. That page could then have the code that checks for reminders and sends them out. It's a bit of a hack, but it should work.
Have a look at Quartz.Net (http://quartznet.sourceforge.net/). You can create an instance of the quartz scheduler in your Application_Start event and as long as the ASP.Net application is running, it will poll the database and trigger any functions you have registered with it. Since you are on a shared host environment, this is probably your best bet unless your hosting provider has a scheduler that can trigger a WebForm (or ASP.Net MVC Controller) periodically.
First you will obviously need to create a user interface and database to store the reminders. That part you got. The next step is to create a service which periodically queries the database for reminders that are due for notification.
The best way to do this is to write a lightweight Windows Service which, as you suggest, uses a loop and a reasonable sleep time (so as not to monopolize the CPU) to continually check the database for reminders and dispatches notifications. It then processes each reminder based on your requirements.
But since you are on shared hosting, you can't deploy a Windows Service, so the next best thing is to run a background thread on Application_Start of your global.asax. There are many examples of how to do this, e.g.:
http://www.west-wind.com/WebLog/posts/67557.aspx
What are some best practices for managing background threads in IIS?
Shared hosting will not work well with what you are trying to do. You could create a background polling thread on Application start, but it will get shut down at some point and may actually be prohibited by your hosting company. An infinite loop will most likely be detected by your hoster and result in your account being automatically shut down, especially if it is using a fair bit of CPU. As John suggests, there may be a scheduled tasks or hosted cron option with your ISP, but generally, those are just for doing things like nightly backups, not really having the level of granularity you need.
Simple answer is, you most likely need something other than a hosted account. You may need to look into a VPS shared hosting service or you may wish to consider looking into MS Azure or Amazon EC2. To do this right, you need to create an application, or better, a service that runs constantly, something a shared hosting account will not provide.
There also a few services out there who can call a specific web page on your service periodically. You could use that to make the page check if there are any reminders that need to be sent.
However since you're then relying on an external site you can't control this might not be the ideal solution if it is very important that the reminders are always being sent.
1) Create a database for storing messages, with a datestamp
2) Create an SQL job, that selects all messages in a time period
3) From the SQL job, you can initialize an .net based SQL Function, that would send out the emails with the System.Net.Mail namespace.
You might consider a 'hack' using the Cache expiration in for triggering events. Create new cache keys that expire at specific Date-Times to run the reminder or make it recur at defined intervals, checking a queue to see if anything new should be sent.
See:
Easy Background Tasks in ASPNET