public static async Task CreatePdfImpl(string conversionId, PdfParameters parameters) { try { var pdf = await CreatePdf.CreatePdfSync(parameters); lock (Jobs) lock (_pdfs) { Jobs[conversionId].status = ConversionJob.Status.Done; _pdfs.Add(conversionId, pdf); } } catch (Exception e) { Console.WriteLine($"{conversionId}: Exception in CreatePdf.CreatePdfSync:"); Console.WriteLine(e); lock (Jobs) { if (Jobs.ContainsKey(conversionId)) { Jobs[conversionId].status = ConversionJob.Status.Error; } } } }
public async Task <IActionResult> CreatePdfSync([FromBody] PdfParameters parameters) { var pdf = await CreatePdf.CreatePdfSync(parameters); return(new FileStreamResult(pdf, "application/pdf") { FileDownloadName = "document.pdf" }); }
public ActionResult <ConversionJob> CreatePdfAsync([FromBody] PdfParameters parameters) { var converionId = Guid.NewGuid().ToString(); var thread = new Thread(new ThreadStart(() => { CreatePdfImpl(converionId, parameters).Wait(); })); thread.Start(); var conversionJob = new ConversionJob(converionId, thread); lock (Jobs) { Jobs.Add(converionId, conversionJob); } return(conversionJob); }