Click here to Skip to main content
15,883,883 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello Experts,

I want to create a automatic email alerts program and I have done it with a button click event. I am sure I know how to create it using windows services also.

Now, I want this program to run only weekly once. On process of finding the absolute simple and perfect approach for this task, I have read "
C#
Imagine creating a service that sits there taking up memory doing absolutely nothing for 7 days, only to run for 4 minutes. Then another 7 days of waiting. While it may work, its certainly not what a service is for.


And also
C#
Use a scheduled task. That scheduled task could easily just start a console app which reads the database, sends the emails, and then quits as normal. Nothing wrong with using a scheduled task for something that... performs a task on a scheduled basis.


And now I don't have any idea of how to create a scheduled task. Could someone help me giving ideas?

Is it just a console application?
How to schedule that?

I have googled and it is redirected to windows services always.

I would appreciate if someone can help me with this notion.

Happy holiday!

Thanks
Posted
Comments
Sergey Alexandrovich Kryukov 21-Dec-15 14:00pm    
Why not Windows Service? Isn't that you don't want develop services due to the associated extra difficulties? If so, you should understand that everything else would be much less reliable.
—SA
sudevsu 21-Dec-15 14:06pm    
No I did develop windows service already. Its running quite good. However, I have read a suggestion that was made by someone that are commented in the question. so I thought lets do a scheduled task
Sergey Alexandrovich Kryukov 21-Dec-15 14:08pm    
Good idea. You can use it on different levels — please see Solution 2 for further detail.
—SA

Yes. It's just a console application that runs in windows task scheduler.

I'm on Windows 10. To get to it, just do a search for Task Scheduler.

I forget how to get to it in other Windows versions. It should be on the start menu under tools or administrative tools.

It's pretty self explanatory once you get there. Just create a new task. Point it to your application exe. and set up a schedule.
 
Share this answer
 
Please see my comment to the question. You really need some service. Other applications would be much easier to terminate, even by accident, which would make them not suitable for scheduling purposes. It doesn't even have to be your own service. Don't you think you would better off using existing service which is designed to support really complex schedules? It is already bundled with Windows and enabled; you can use it on different levels. It is called Window Task Scheduler, see http://en.wikipedia.org/wiki/Windows_Task_Scheduler[^].

First, you can schedule events using command-line utilities AT.EXE or CSHTASKS.EXE (which is replacing AT.EXE), see:
http://en.wikipedia.org/wiki/At_%28Windows%29[^],
http://en.wikipedia.org/wiki/Schtasks[^],
http://technet.microsoft.com/en-us/library/bb490866.aspx[^],
http://msdn.microsoft.com/en-us/library/windows/desktop/bb736357%28v=vs.85%29.aspx[^].

And you also can use Window Task Scheduler API, please see:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa383614%28v=vs.85%29.aspx[^],
http://msdn.microsoft.com/en-us/library/windows/desktop/aa383608%28v=vs.85%29.aspx[^].

To see how can you use it with .NET, see this CodeProject article: A New Task Scheduler Class Library for .NET[^].

As to the service development: the most difficult problem is hardness in their debugging. In response to this problem, I developed some technique of dual-use application development: the same application can be executed either interactively or as hosted by a service controller. This way, most of the debugging can be performed in the interactive mode, which is, of course, is much easier. I explained this technique in my past answer: Configure Windows Service with UI[^].

Happy holidays!

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900