我正在用几个位图构建一个位图。我所做的是调用多个返回任务的方法。
我遇到的问题是死锁,因为我试图通过 .Result 从 .ContinueWith() 中的异步方法中检索值,但这不起作用,因为它将异步方法转换为sync 方法,这导致我陷入僵局。
我的问题是如何调用 .ContinueWith 中的异步方法,或者实现此类方法的正确方法是什么?
我需要删除 .Result 并正确调用异步方法 Task 。正确的方法是什么?
这是我的代码。
public async static Task<Bitmap> RollUpDrawingsImage(IElevation elevation)
{
int height = 0, width = 800;
Bitmap completeDrawings = null;
using (Bitmap elevationDoor = await ShopDrawing.Merger.MergeElevationAndDoor(elevation, RotateFlipType.Rotate90FlipNone))
{
using (Bitmap partsList = await MaterialsList.Manager.GetMaterialList(elevation).ContinueWith(async (ml) => await ml.Result.GetDrawing()).Result)
{
using (Bitmap optimized = await Optimization.Manager.GetOptimizedParts(elevation).ContinueWith(async (op) => await op.Result.GetDrawing()).Result)
{
using (Bitmap cutSheet = await CutSheet.Manager.GetCutSheet(elevation).ContinueWith(async (cs) => await cs.Result.GetDrawing()).Result)
{
height = (elevationDoor.Height + optimized.Height + cutSheet.Height + partsList.Height);
completeDrawings = new Bitmap(width, height + 40);
using (var dc = Graphics.FromImage(completeDrawings))
{
dc.DrawImageUnscaled(elevationDoor, 0, 0);
dc.DrawImageUnscaled(partsList, 0, elevationDoor.Height + 10);
dc.DrawImageUnscaled(optimized, 0, (elevationDoor.Height + partsList.Height) + 20);
dc.DrawImageUnscaled(cutSheet, 0, (elevationDoor.Height + partsList.Height + optimized.Height) + 30);
};
return completeDrawings;
}
}
}
};
}