积极答复者
异步打印时,打印顺序错乱

问题
-
需求是这样的,每次打印时可以选择需要打印的页数,和复件数。但是由于打印耗时过长,我将打印功能设为了异步;但是异步打印出来的东西顺序时错乱的:当打印一组2页,2复件的标签后,再打印一组2页,2复件的标签时,后一组标签会随机插入到前一组的顺序,混乱打印。可能造成的原因是和printing queue有关?我把代码贴出来,希望能提供一些解决的方法或者思路。谢谢!
ReportProcessor reportProcessor = new ReportProcessor(); UriReportSource uriReportSource = new UriReportSource(); TypeReportSource typeReportSource = new TypeReportSource(); PrinterSettings printerSettings = new PrinterSettings(); PrintController standardPrintController = new StandardPrintController(); string AppPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); public async Task MultiTagsPrint(TagInfo tagInfo,string PrinterName) // print tag { await Task.Run(() => { reportProcessor.PrintController = standardPrintController; uriReportSource.Uri = AppPath + string.Format(@"\{0}.trdp", PrinterName); //定义TELERIK 标签设计文件路径 printerSettings.PrinterName = PrinterName; typeReportSource.TypeName = AppPath + string.Format(@"\{0}.trdp", PrinterName); //定义TELERIK 标签设计文件路径 uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter("Line1", tagInfo.Header)); uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter("Line2", tagInfo.body)); reportProcessor.PrintReport(uriReportSource, printerSettings); }); }
- 已编辑 CZAupup 2018年12月18日 17:00 无效代码
答案
-
Hi Cherry BU,
我找到问题的所在了,我的打印功能是再另一条线程上的,当第一个文档正在打印时,第二个文档会顶替掉第一个文档再打印机序列的首位顺序。有什么方法可以规定打印文档的添加顺序吗?下面是我的代码
private void MultiTagsPrint() // print tag { ReportProcessor reportProcessor = new ReportProcessor(); ReportBook reportBook = new ReportBook(); PrinterSettings printerSettings = new PrinterSettings(); PrintController standardPrintController = new StandardPrintController(); string AppPath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); reportProcessor.PrintController = standardPrintController; printerSettings.PrinterName = "StickyTag"; for (int i = 0; i < 2; i++) { Dispatcher.Invoke(() => { foreach (var tagInfo in PrinterParameters()) { UriReportSource uriReportSource = new UriReportSource(); uriReportSource.Uri = AppPath + string.Format(@"\{0}.trdp", "StickyTag"); uriReportSource.Parameters.Add("Line1", tagInfo.DeptName); reportBook.ReportSources.Add(uriReportSource); } }); var bookIRS = new InstanceReportSource { ReportDocument = reportBook }; reportProcessor.PrintReport(bookIRS, printerSettings); } }
- 已建议为答案 Zhanglong WuMicrosoft contingent staff 2018年12月21日 8:32
- 已标记为答案 CZAupup 2019年1月4日 17:17
全部回复
-
Hi CZAupup,
关于打印队列的问题, 我建议你可以看一下MSDN文档:
https://docs.microsoft.com/zh-cn/dotnet/framework/wpf/advanced/printing-overview
Best Regards,
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com. -
Hi Cherry BU,
我找到问题的所在了,我的打印功能是再另一条线程上的,当第一个文档正在打印时,第二个文档会顶替掉第一个文档再打印机序列的首位顺序。有什么方法可以规定打印文档的添加顺序吗?下面是我的代码
private void MultiTagsPrint() // print tag { ReportProcessor reportProcessor = new ReportProcessor(); ReportBook reportBook = new ReportBook(); PrinterSettings printerSettings = new PrinterSettings(); PrintController standardPrintController = new StandardPrintController(); string AppPath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); reportProcessor.PrintController = standardPrintController; printerSettings.PrinterName = "StickyTag"; for (int i = 0; i < 2; i++) { Dispatcher.Invoke(() => { foreach (var tagInfo in PrinterParameters()) { UriReportSource uriReportSource = new UriReportSource(); uriReportSource.Uri = AppPath + string.Format(@"\{0}.trdp", "StickyTag"); uriReportSource.Parameters.Add("Line1", tagInfo.DeptName); reportBook.ReportSources.Add(uriReportSource); } }); var bookIRS = new InstanceReportSource { ReportDocument = reportBook }; reportProcessor.PrintReport(bookIRS, printerSettings); } }
- 已建议为答案 Zhanglong WuMicrosoft contingent staff 2018年12月21日 8:32
- 已标记为答案 CZAupup 2019年1月4日 17:17