Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

wpf - Periodic execution of particular code in c#

I've a set of queries which I want to execute only once in day, I know this is possible using TaskScheduler in C#. But I am not getting any example suitable for my requirements. Can anybody give a example code for this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can try FluentScheduler. The documentation has the sample codes all you need. Firstly I thought it is for web only, but now I think you can use it for using with Desktop Application too. But not sure and not tested.

https://fluentscheduler.codeplex.com/documentation

EDIT You can also use Task Scheduler -

  1. First create a console application that can run and do all your tasks. You can even invoke other processes with it. Then build the executable and save it in a safe location.

  2. Then go to Administrative Tools > Task Sheduler And create a new task by clicking Action > New Task. You will see a screen like this -

enter image description here

Select your executable and other permissions there.

  1. Now to run it in schedule move to next tab 'Triggers' and click add at the bottom. You will see a screen like this -

enter image description here

Now add your desired schedules. Make sure you use logs, because you will not be able to see the outputs directly. Either you can use windows event viewer or write to custom text file for your convenience.

Task Scheduler is a part of windows itself. It does not have a dependency on C# or C++ anything. Basically you tell windows that it will run the specific program at a regular schedule. It is the job of the executed program to initialize all environment and execute appropriate code. So even if you use task scheduler you have to make sure that the program you are using to run with it, has all other options and codes right.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...