public async void CheckPrinterAndCreateWorksheet() { if (IsWorksheetCreated) { return; } Logging.ToLog("ItemPatient - создание книги со списком назначений"); IsWorksheetCreatingStarted = true; await Task.Run(() => { printerState = PrinterInfo.Instance.GetPrinterState(); Logging.ToLog("ItemPatient - Полученный статус принтера: " + printerState); try { if (printerState == PrinterInfo.State.DoNotCheck || printerState == PrinterInfo.State.Ready) { worksheet = ExcelInterop.Instance.CreateWorksheetAppointments(this, out workbook); } } catch (Exception e) { printerState = PrinterInfo.State.NotPrinted; Logging.ToLog(e.Message + Environment.NewLine + e.StackTrace); } IsWorksheetCreated = true; BackgroundWorkCompletedEvent.Set(); }).ConfigureAwait(false); }
public PrinterInfo.State PrintAppointmentsAvailable() { Logging.ToLog("ItemPatient - печать списка назначений"); if (!IsWorksheetCreatingStarted) { CheckPrinterAndCreateWorksheet(); } if (!IsWorksheetCreated) { BackgroundWorkCompletedEvent.WaitOne(); } if (printerState.HasValue) { switch (printerState.Value) { case PrinterInfo.State.NotSelect: case PrinterInfo.State.NotFound: case PrinterInfo.State.Error: return(printerState.Value); } if (worksheet == null) { return(PrinterInfo.State.NotPrinted); } try { ExcelInterop.Instance.PrintWorksheetAndCloseWorkbook(ref worksheet, ref workbook); return(PrinterInfo.State.Printed); } catch (Exception e) { Logging.ToLog(e.Message + Environment.NewLine + e.StackTrace); return(PrinterInfo.State.NotPrinted); } } return(PrinterInfo.State.Unknown); }