Out of everything for this project I'm on this is the portion that scares me the most.
I want to share to you what I've got and at least I can know that I've got the basics of what needs to be done.
I'm also going to share with you another type of async approach and it is with the using(){}. I cannot apply the await because it keeps asking for the .Result
---Here is the one that I'm assuming that is multithreading, and the one you've helped me with, and I'll tell you there is a whole hell of a lot of work going on for each one of those function call and or Task<>
public
async
static
Task<PdfSharp.Pdf.PdfDocument> RollUpDrawingsPDF(IElevation elevation)
{
List<Bitmap> allSheets =
new
List<Bitmap>();
//elevation
allSheets.Add(await ShopDrawing.Manager.GetShopDrawing(elevation,
true
, RotateFlipType.Rotate90FlipNone));
//door schedules, 3 schedules per sheet
allSheets.AddRange(await ShopDrawing.Door.GetDoorSecheduleSheets(elevation, RotateFlipType.Rotate90FlipNone, 3));
//materials list
allSheets.Add(await MaterialsList.Manager.GetMaterialList(elevation).GetDrawing());
//optimized parts
allSheets.Add(await Optimization.Manager.GetOptimizedParts(elevation).GetDrawing());
//cut sheet
allSheets.Add(await CutSheet.Manager.GetCutSheet(elevation).GetDrawing());
return
await PDFMaker.PDFManager.GetPDF(allSheets,
true
);
}
----------------------Now here is a different type of scenario: This one returns one Bitmap drawn from a collection of Bitmaps and returns 1 image, unlike the one above that returns 1 PDF Document with different PDF Sheets---------------------------------------------
public
async
static
Task<Bitmap> RollUpDrawingsImage(IElevation elevation)
{
int
height = 0, width = 800;
Bitmap completeDrawings =
null
;
return
await Task.Run(() =>
{
using
(Bitmap elevationDoor = ShopDrawing.Merger.MergeElevationAndDoor(elevation, RotateFlipType.Rotate90FlipNone).Result)
{
using
(Bitmap partsList = MaterialsList.Manager.GetMaterialList(elevation).GetDrawing().Result)
{
using
(Bitmap optimized = Optimization.Manager.GetOptimizedParts(elevation).GetDrawing().Result)
{
using
(Bitmap cutSheet = CutSheet.Manager.GetCutSheet(elevation).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;
});
}
**Notice for this one above that I cannot apply the await operator in from of the .GetDrawing()?
I've got to use the .Result to get the result.
What type of effect am I having on my code?
Should I be using the result? Or designing my code like for the RollUpDrawingsPDF() function?
I know I'm banging you up for questions, but this is one of the most important parts of the last two years of work I've put into this one app. So, I'm very grateful for your help!
Erik