C#调用timer.Elapsed时报错返回类型错误。
请求IT界Big佬们提示!
static void Main(string[] args)
{
System.Timers.Timer timer = new System.Timers.Timer();
timer.Enabled = true;
timer.Interval = 6000;
timer.Start();
timer.Elapsed += new ElapsedEventHandler(r1);
Console.ReadKey();
}
private static async Task r1(object source, ElapsedEventArgs e)
{
String Message = "";
//调试SQL事件,输出SQL语句
Chormadb.Aop.OnLogExecuting = (sql, pars) =>
{
Console.WriteLine("Sql语句:" + sql);
Console.WriteLine(string.Join(",", pars?.Select(it => it.ParameterName + ":" + it.Value)));
};
Baizedb.Aop.OnLogExecuting = (sql, pars) =>
{
Console.WriteLine("Sql语句:" + sql);
Console.WriteLine(string.Join(",", pars?.Select(it => it.ParameterName + ":" + it.Value)));
};
//查询Chroma数据生成list文件
var list = await Chormadb.Queryable<LCR_REEL>()
.Where(x => x.CreateUserID == "1223876")//string.IsNullOrEmpty(x.Remark1) == true
.Take(10)
.ToListAsync();
#region//for循环插入数据到baize
try
{
foreach (var item in list)
{
//查询baize有没有
var has = await Baizedb.Queryable<MC_LCR_REEL>().Where(x => x.Reel_Id == item.Reel_Id).CountAsync();
if (has <= 0)
{
var InsertSN = new MC_LCR_REEL();
{
InsertSN.ID = Sys.Guid;
InsertSN.Reel_Id = item.Reel_Id;
InsertSN.Part_No = item.Part_No;
InsertSN.Result = item.Result;
InsertSN.Value = item.Value;
InsertSN.Unit = item.Unit;
InsertSN.Enabled = 1;
InsertSN.CreateDate = item.CreateDate;
InsertSN.CreateUserID = item.CreateUserID;
InsertSN.ModifyUserID = item.ModifyUserID;
InsertSN.ModifyDate = item.ModifyDate;
}
Baizedb.Insertable(InsertSN).ExecuteCommand();
Message = "successful";
}
else
{
Console.WriteLine($"{item.Reel_Id}已存在");
}
}
}
catch (Exception ex)
{
Console.WriteLine("Exception Message: " + ex.Message);
Message = ex.Message;
};
#endregion
#region for循环,插入到Baize库后添加标识到Chroma库
if (Message == "successful")
{
foreach (var item in list)
{
var uptedateSN = new LCR_REEL();
{
uptedateSN.Remark1 = "Y";
}
Chormadb.Updateable<LCR_REEL>()
.SetColumns(it => it.Remark1 == "Y")
.Where(it => it.Reel_Id == item.Reel_Id)
.ExecuteCommand();
}
}
#endregion
Console.WriteLine($"执行完成");
Console.ReadKey();
}