/// <summary> /// Callback method that is called when printing completes (successfully or as a result of failure). /// </summary> /// <param name="_">The Print Interaction controller</param> /// <param name="completed">Flag indicating if printing has completed.</param> /// <param name="nsError">NSError value used to report errors during printing. Null if no error.</param> private static async void PrintCompletion( UIPrintInteractionController _, bool completed, NSError nsError) { try { if (completed) { await PrintStatusReporting.ReportInfoAsync( CrossPrinting.PrintingMessages.PrintInteractionCompleted); } else if (!completed && nsError != null) { await PrintStatusReporting.ReportInfoAsync( CrossPrinting.PrintingMessages.PrintInteractionError); } } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) { await PrintStatusReporting.ReportExceptionAsync(ex); } #pragma warning restore CA1031 // Do not catch general exception types }
/// <summary> /// Show Print Preview UI /// </summary> /// <returns>Task that the caller is expected to await</returns> protected async Task ShowPrintApiAsync() { try { if (await RegisterForPrintingAsync()) { bool showprint = await Windows.Graphics.Printing.PrintManager.ShowPrintUIAsync(); } else { UnwireAllEvents(); } } #pragma warning disable CS0168 // Variable is declared but never used catch (System.IO.FileNotFoundException fnfex) #pragma warning restore CS0168 // Variable is declared but never used { UnwireAllEvents(); await PrintStatusReporting.ReportInfoAsync( CrossPrinting.PrintingMessages.PrinterServiceBusy); return; } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) { if ((ex.Message != null) && (ex.Message.Contains("0x80010115"))) { // {"OLE has sent a request and is waiting for a reply. (Exception from HRESULT: 0x80010115)"} await PrintStatusReporting.ReportInfoAsync( CrossPrinting.PrintingMessages.AwaitingResponse); UnwireAllEvents(); return; } else { await PrintStatusReporting.ReportExceptionAsync(ex); UnwireAllEvents(); return; } } #pragma warning restore CA1031 // Do not catch general exception types }