问题描述
我尝试在某些PC上遵循以下代码.
I tried following code on some PCs.
using (var lps = new LocalPrintServer())
using(var pqueue = lps.GetPrintQueue("PRINTER-NAME"))
{
pqueue.AddJob("job-name", @"C:\example.xps", false, pticket);
}
仅在一台PC上,它不起作用.应用程序冻结在 AddJob
方法.即使等待了很长时间,它也从未完成.没有例外.
On only one PC, it did not work.The application froze at AddJob
method.It never finished even after waiting for long time.There are no exceptions.
发生此问题的PC是Windows10,并应用了CreatorsUpdate.其他PC是应用了AnniversaryUpdate的Windows7,Windows8.1和Windows10.
The PC where this problem occurred is Windows10 and applied CreatorsUpdate.Other PCs are Windows7, Windows8.1 and Windows10 applied AnniversaryUpdate.
此问题是CreatorsUpdate的错误吗?
Is this problem a bug of CreatorsUpdate?
补充:
具有CreatorsUpdate的PC可以通过此代码打印xps文件.
Supplement:
The PC which has CreatorsUpdate can print xps file by this code.
using (var lps = new LocalPrintServer())
using(var pqueue = lps.GetPrintQueue("PRINTER-NAME"))
using (var doc = new XpsDocument(@"C:\example.xps", System.IO.FileAccess.Read))
{
var writer = PrintQueue.CreateXpsDocumentWriter(pqueue);
var docSeq = doc.GetFixedDocumentSequence();
writer.Write(doc, pticket);
}
推荐答案
我确定目标打印机驱动程序不是基于XPS的.我对此有同样的问题.
I am sure that the target printer driver is not XPS based. I had the same problem with that.
您可以先通过以下方法检查打印机的兼容性:
You may first check the compatibility of the printer through:
LocalPrintServer server = new LocalPrintServer(PrintSystemDesiredAccess.AdministrateServer);
PrintQueue queue = server.GetPrintQueue("MyPrinterName");
MessageBox.Show(queue.IsXpsDevice.ToString());
如果结果为假,那就是原因.
If the result is false, then that's why.
这篇关于`PrintQueue.AddJob`尚未完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!