ITsolutionWizard
asked on
c#, timer
In my console application, I will like to do something like
begin
at 1:00 am pst daily
run the program (it is just a query run with smtp email sent to the client)
end
Overall, the program is not a big deal. I just want to know how to code at 1:00 am pst daily in timer property in c#.
Thanks,
begin
at 1:00 am pst daily
run the program (it is just a query run with smtp email sent to the client)
end
Overall, the program is not a big deal. I just want to know how to code at 1:00 am pst daily in timer property in c#.
Thanks,
Simply program Windows Task Scheduler to start your application at the desired time.
ASKER
No I want to do it in codes
In order to do it in code, you need to create a service, that runs all the time, for an operation that happens only once a day. It not a very good idea.
ASKER
I already created the service.
create an application with a timer having the Tick event raised every 10 seconds (or your own interval) and check what time it is.
ASKER
Éric Moreau: code samples please
Have you looked into Quartz.NET yet? I haven't yet used it myself, but from what I understand it is the code equivalent of Task Scheduler.
something like this:
using System;
using System.Diagnostics;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private Timer _timer = new Timer();
private DateTime _lastDateProcessed = DateTime.MinValue;
public Form1()
{
InitializeComponent();
_timer.Interval = 10000;
_timer.Tick += _timer_Tick;
_timer.Enabled = true;
}
void _timer_Tick(object sender, EventArgs e)
{
if ((DateTime.Now.Hour == 1) && (_lastDateProcessed != DateTime.Today.Date))
{
_lastDateProcessed = DateTime.Today.Date; //to be sure we are not reprocessing in the same day
Process.Start("FullPathToYourApplication");
}
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.