我想实现一个async功能。我的问题是;我不知道在下面的代码中将await关键字放在哪里:
public async Task<List<ManualReadTag>> GetManuallyReadTags(ParameterManualTags model)
{
var db = new ApplicationDbContext();
using (var cnxn = db.Database.Connection)
{
cnxn.Open();
var cmd = cnxn.CreateCommand();
cmd.CommandText = "GetManualReadForDedicated";
cmd.CommandType = CommandType.StoredProcedure;
var dtFrom = cmd.CreateParameter();
dtFrom.ParameterName = "@DateFrom";
dtFrom.DbType = DbType.Date;
dtFrom.Direction = ParameterDirection.Input;
dtFrom.Value = model.DateFrom;
var dTo = cmd.CreateParameter();
dTo.ParameterName = "@DateTo";
dTo.DbType = DbType.Date;
dTo.Direction = ParameterDirection.Input;
dTo.Value = model.DateTo;
var lane = cmd.CreateParameter();
lane.ParameterName = "@Lane";
lane.DbType = DbType.Int32;
lane.Direction = ParameterDirection.Input;
lane.Value = model.Lane;
var plaza = cmd.CreateParameter();
plaza.ParameterName = "@Plaza";
plaza.DbType = DbType.String;
plaza.Direction = ParameterDirection.Input;
plaza.Value = model.Plaza;
cmd.Parameters.Add(dtFrom);
cmd.Parameters.Add(dTo);
cmd.Parameters.Add(lane);
cmd.Parameters.Add(plaza);
try
{
using (var reader = cmd.ExecuteReader())
{
var result = ((IObjectContextAdapter) db)
.ObjectContext
.Translate<ManualReadTag>(reader)
.ToList();
return result;
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
MessageBox.Show(ex.Message);
return null;
}
}
}
这段代码有效,我只需要输入 intawait关键字,这样我就可以使用async. 您能指出我正确的方法吗?
神不在的星期二
拉莫斯之舞
相关分类