C # run code every 30 days

If I needed to run some code, maybe send an email every 30 days to users of my site, how to do it?

+7
source share
5 answers

What structure do you work with? I have some pointers if you are working with .Net 4.0, like me.

If you have access to your computer where you can install the services, I would use a new and improved Workflow service for this situation. What is nice about them is that Workflows can persist for several minutes, hours, days, weeks, months, etc., Lying โ€œinactive,โ€ until the delay time periods are over.

If it is an IIS machine (and if you want to use this route), then it is relatively simple to build it directly as a project / solution "Workflow Service" in VS 2010. From there you will be presented by the designer and several workflow actions on the toolbar.

Add flowchart activity to put your email actions inside. The flowchart is ideal because it can initialize everything you need, and the flow of decisions can redirect backward in the direction (in contrast to the activity of an always moving sequence). What you need to do with your logic is up to you because your question does not contain many details.

Now, if you are using .Net 3.5, I would think about refraining from creating Workflow, since you need to migrate when switching to 4.0 (WF 3.5 is NOT compatible with 4.0). When the administrator accesses the computer, you can install the Windows service, which contains a timer, to light up the code every 30 days (or, nevertheless, determined) as necessary.

+1
source share

Use the Windows Task Scheduler to launch your application.

+19
source share

Options:

1) A console application that runs in the Windows Task Scheduler

2) Windows Service http://www.c-sharpcorner.com/UploadFile/mahesh/window_service11262005045007AM/window_service.aspx

+4
source share

If it is a specific SQL Server, you can use SQL Jobs .

+1
source share

If you want to do this with your ASP.NET application instead of a standalone application, you have several options:

Since you want it to run every 30 days, rather than daily, I recommend this method of using a schedule table instead of application variables or a cache for scheduling tasks:

You can set up a schedule table in your db and check when it was last updated in your global.asax. At the beginning of the session, check if the current date exceeds 30 days. If so, then call the method of sending letters.

If you are sending emails, update the schedule table with the current date.

+1
source share

All Articles