我创建了一个在后台特定时间执行 exe 的服务。我想设置一个计时器,使服务每天同时执行 exe.. 怎么能做到..??? 这是我在服务类中编写的代码:
public partial class Service1 : ServiceBase
{
string time = DateTime.Now.ToShortTimeString();
Process p = new Process();
public Service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
BackgroundWorker bw = new BackgroundWorker();
bw.DoWork += new DoWorkEventHandler(DoWork);
bw.RunWorkerAsync();
}
private void DoWork(object sender, DoWorkEventArgs e)
{
p.StartInfo = new ProcessStartInfo(@"c:\windows\ccm\ccmeval.exe");
if (time == "6:55 PM")
{
p.Start();
p.WaitForExit();
base.Stop();
}
}
protected override void OnStop() { }