private async void SendFileButton_Clicked(object sender, EventArgs eventArgs) { SetInputEnabled(false); string filePath = null; Connection connection = null; try { await Task.Factory.StartNew(() => { connection = CreateConnection(); connection.Open(); ZebraPrinter printer = ZebraPrinterFactory.GetInstance(connection); filePath = CreateDemoFile(printer.PrinterControlLanguage); printer.SendFileContents(filePath); }); } catch (Exception e) { await DisplayAlert("Error", e.Message, "OK"); } finally { try { connection?.Close(); } catch (ConnectionException) { } if (filePath != null) { try { new FileInfo(filePath).Delete(); } catch (Exception) { } } SetInputEnabled(true); } }
//ๅ้ๆไปถ public static bool SendFile(string filePath) { if (printer != null && filePath != "") { printer.SendFileContents(filePath); return(true); } return(false); }
private void SendFileToPrinter() { string filePath = null; Connection printerConnection = null; Task.Run(() => { try { printerConnection = connectionSelector.GetConnection(); printerConnection.Open(); ZebraPrinter printer = ZebraPrinterFactory.GetInstance(printerConnection); filePath = CreateDemoFile(printer.PrinterControlLanguage); printer.SendFileContents(filePath); } catch (ConnectionException e) { MessageBoxCreator.ShowError(e.Message, "Connection Error"); } catch (IOException e) { MessageBoxCreator.ShowError(e.Message, "IO Error"); } catch (ZebraPrinterLanguageUnknownException e) { MessageBoxCreator.ShowError(e.Message, "Connection Error"); } catch (Exception e) { MessageBoxCreator.ShowError(e.Message, "Send File Error"); } finally { try { if (printerConnection != null) { printerConnection.Close(); } } catch (ConnectionException) { } if (filePath != null) { try { new FileInfo(filePath).Delete(); } catch { } } SetSendFileButtonState(true); } }); }