Task的用法

推荐几篇写的很好的文章,本文部分转自:

https://www.cnblogs.com/zhaoshujie/p/11082753.html

https://www.cnblogs.com/xiaojidanbai/p/13224172.html

写法1:

new Task(StartCode, model.EquipID).Start();

private static void StartCode(object EquipID)
{
try
{
BaseManager bm = new BaseManager();
var sql = @"exec sp_ExportFANew '" + EquipID + "'";
var rx = bm.ExecuteCommand(sql);
Console.WriteLine(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") +"sp_ExportFAJDENew sucess:" + EquipID );
}
catch (Exception e)
{
Console.WriteLine(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "sp_ExportFAJDENew sucess:" + EquipID, e);
}
}

写法2:

System.Threading.Tasks.Task apitask = new System.Threading.Tasks.Task(() =>
{
result.Data = bm.StartCode(no);
});
apitask.Start();

写法3:
Task.Factory.StartNew(() =>
{
result.Data = bm.StartCode(OAno);
});

上一篇:基于wine葡萄酒数据集的分类方法研究


下一篇:序列比对(25)编辑距离