我现在在做一个windows service 实现一个合同的指定天数提醒,这个合同在一个用asp.net和c#实现的web网站中。我是通过在windows服务中用一个timer3秒钟去读数据库中设定的时间,如果设定的时间和我现在的时间相等,发通知提醒合同即将到期。
service1.cs中的代码如下:
运行时就是出现如下的错误:无法将文件“obj\x86\Debug\KYPT.exe”复制到“bin\Debug\KYPT.exe”。文件“bin\Debug\KYPT.exe”正由另一进程使用,因此该进程无法访问此文件
我在计算机管理-》服务中把这个服务关掉。提示我需要开启服务。我要是开启服务就会出现上面的错误。但是我的服务时必须要开启的要不让不会定时从数据库中读数据啊 哪位大侠给解决一下!万分感谢!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using Model;
using service;
using System.Data.SqlClient;namespace KYPT
{
public partial class Service1 : ServiceBase
{
public Service1()
{
InitializeComponent();
} protected override void OnStart(string[] args)
{
timer1.Interval = 1000;
timer1.Enabled = true;
} protected override void OnStop()
{
timer1.Enabled = false;
timer1.Stop();
} private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
timer1.Enabled = false;
InformSrv bs = new InformSrv();
List<InformInfo> listcontact = bs.getremindertime();
listcontact.ForEach(c =>
{
DateTime dt1 = DateTime.Now;
DateTime dt2 = Convert.ToDateTime(c.ProRemindTime);
TimeSpan span = dt1 - dt2;
BaseSrv<InformInfo> inform = new BaseSrv<InformInfo>();
if (span.TotalSeconds == 0)
{
InformInfo inf = new InformInfo();
inf.PTypeName = c.PTypeName;
inf.PType = c.PType;
inf.IsApply = 1;
inform.add(inf); }
});
timer1.Enabled = true;
}
}
}
另外: timer1_Elapsed 的最后一句 timer1.Enabled = true 有问题,应去掉。