Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# `PrintQueue.AddJob`未完成_C#_.net_Printing_Windows 10 - Fatal编程技术网

C# `PrintQueue.AddJob`未完成

C# `PrintQueue.AddJob`未完成,c#,.net,printing,windows-10,C#,.net,Printing,Windows 10,我在一些电脑上尝试了以下代码 using (var lps = new LocalPrintServer()) using(var pqueue = lps.GetPrintQueue("PRINTER-NAME")) { pqueue.AddJob("job-name", @"C:\example.xps", false, pticket); } 仅在一台PC上,它无法工作。 应用程序冻结在AddJob方法。 即使等了很长时间也没有完成。 没有例外 出现此问题的电脑是Windows1

我在一些电脑上尝试了以下代码

using (var lps = new LocalPrintServer())
using(var pqueue = lps.GetPrintQueue("PRINTER-NAME"))
{
    pqueue.AddJob("job-name", @"C:\example.xps", false, pticket);
}
仅在一台PC上,它无法工作。 应用程序冻结在
AddJob
方法。 即使等了很长时间也没有完成。 没有例外

出现此问题的电脑是Windows10和applied CreatorUpdate。 其他电脑包括Windows7、Windows8.1和Windows10应用周年更新

这个问题是CreatorUpdate的bug吗

补充资料:
具有CreatorUpdate的PC可以使用此代码打印xps文件

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的。我也有同样的问题

您可以首先通过以下方式检查打印机的兼容性:

LocalPrintServer server = new LocalPrintServer(PrintSystemDesiredAccess.AdministrateServer);
PrintQueue queue = server.GetPrintQueue("MyPrinterName");            
MessageBox.Show(queue.IsXpsDevice.ToString());

如果结果为假,那就是原因。

我遇到了同样的问题。这种情况只发生在某些机器上,其他机器似乎没有问题。我发现使用AddJob获取PrintSystemJobInfo对象,然后将XPS文件流式传输到其JobStream更可靠。这可能是Windows的问题10@blz你的代码救了我的命,解决了我机器上的打印问题