Description:-
The Task Scheduler allows
you to create all kinds of automated tasks in Windows. You can schedule a
program to run at a specific time interval, a message to be displayed when
something happens and so on. You can schedule just about anything with it. The
only limit is your imagination.
You must be logged on as an
administrator to perform these steps. If you aren't logged on as an
administrator, you can only change settings that apply to your user account.
If you use a specific program
on a regular basis, you can use the Task Scheduler wizard to create a task that
opens the program for you automatically according to the schedule you choose.
For example, if you use a financial program on a certain day each month, you
can schedule a task that opens the program automatically to avoid the risk of
forgetting to open it yourself.
1.
Open
Task Scheduler by clicking the Start button, clicking Control Panel, clicking
System and Security, clicking Administrative Tools, and then double-clicking
Task Scheduler. If you're prompted for an administrator password or
confirmation, type the password or provide confirmation.
2.
Click
the Action menu, and then click Create Basic Task.
3.
Type
a name for the task and an optional description, and then click next.
4.
Do
one of the following:
- To select a schedule based on the calendar, click Daily, Weekly, Monthly, or one time, click next; specify the schedule you want to use, and then click next.
- To select a schedule based on common recurring events, click when the computer starts or When I log on, and then click next.
- To select a schedule based on specific events, click when a specific event is logged, click next; specify the event log and other information using the drop-down lists, and then click next.
- To schedule a program to start automatically, click Start a program, and then click next.
5.
Click
Browse to find the program you want to start, and then click next.
6.
Click
Finish.
To schedule a task
to run automatically when the computer starts
If you want a task to run
when the computer starts, whether a user is logged on or not, follow these
steps.
1. Open
Task Scheduler by clicking the Start button, clicking Control Panel, clicking
System and Security, clicking Administrative Tools, and then double-clicking
Task Scheduler. If you're prompted for an administrator password or
confirmation, type the password or provide confirmation.
2.
Click
the Action menu, and then click Create Basic Task.
3.
Type
a name for the task and an optional description, and then click next.
4.
Click
when the computer starts, and then click next.
5.
To
schedule a program to start automatically, click Start a program, and then
click next.
6.
Click
Browse to find the program you want to start, and then click next.
7.
Select
the Open the Properties dialog for this task when I click Finish check box and
click Finish.
8.
In
the Properties dialog box, select Run whether user is logged on or not, and
then click OK.
As in the
preceding scenario we can have multiple solutions for that:
1.
Create a Windows Service, implement your logic and a set
timer.
2.
Create a console application and implement your logic, then
create a scheduler and refer action as console application .exe file.
3.
Any third-party scheduler like Quartz scheduler.
Here we will explain use of a
console application with the Windows Scheduler.
First we need to create a console
application in Visual Studio. Please see the following screenshot, I have
created a console app with starter logic:
static void Main(string[] args) { RunScheduler(); } public static void RunScheduler() { string path = Path.GetFullPath("D:\\MyTest") + "\\" + DateTime.Now.ToString("MM_dd_yyyy_HH_mm") + "_Log.txt"; try { if (!File.Exists(path)) { File.Create(path); } } catch (Exception ex) { string errorpath = @"D:\MyTest.txt"; File.AppendAllText(errorpath, Environment.NewLine + ex.Message); } }
After implementing our logic
we need to build the application in release mode. Once it builds successfully,
it creates one .exe file in your directory.
Now my application is ready
for setting up in the Windows Scheduler.
Before you start the
scheduler you should have Admin Rights in system.
To open Windows Scheduler go
to the Start menu and in the search box type "Scheduler", then it
will display the Task Scheduler. Click on that.
Now create your task
Scheduler for Repeats every 1 minute.
After Check your Folder you
can get every minute new text file in your folder.
Thanks for comments.....