因为它不尊重等待
public async Task Save(Ticket header, TicketLines newLines)
{
Debug.WriteLine("init save");
await dbConnection.RunInTransactionAsync(new Action<SQLite.Net.SQLiteConnection>(tran =>
{
dbConnection.InsertAsync(header).ContinueWith((t) =>
{
Debug.WriteLine("-> New header ID: {0}", header.Id);
foreach (var item in newLines)
{
item.DocumentId = = header.Id;
}
dbConnection.InsertAllAsync(newLines);
});
//tran.Commit();
}));
Debug.WriteLine("End Save");
}
订购调试
答案 0 :(得分:-1)
你有两个没有等待的异步调用(你之前没有await关键字)
public Save(Ticket header, TicketLines newLines) {
Debug.WriteLine("init save");
dbConnection.RunInTransactionAsync(new Action<SQLite.Net.SQLiteConnection>(tran =>
{
dbConnection.Insert(header).ContinueWith((t) =>
{
Debug.WriteLine("-> New header ID: {0}", header.Id);
foreach (var item in newLines)
{
item.DocumentId = = header.Id;
}
dbConnection.InsertAll(newLines);
});
//tran.Commit();
}));
Debug.WriteLine("End Save");
}