xpsドキュメントをプリンタ(ネットワークプリンタ、いくつかの仮想ローカルプリンタ、xpsベースおよび非xpsベース)に次のコードで印刷しようとしています。PrintQueue.AddJobが非xpsベースのプリンタに印刷するときにハングします
C#のソース:
static void Main(string[] args)
{
PrintServer printServer = new PrintServer(@"\\printserver.csez.zohocorpin.com");
foreach (PrintQueue queue in printServer.GetPrintQueues())
{
Console.WriteLine("Printer: {0}, Port: {1}, ShareName: {2}, status: {3}, PrintingIsCancelled: {4}",
queue.Name, queue.QueuePort.Name, queue.ShareName, queue.QueueStatus, queue.PrintingIsCancelled);
Program program = new Program();
Thread printingThread = new Thread(() => program.Print_XPXFile(queue, @"D:\Assist\RemotePrint\Spool\Donalduck.xps"));
// Set the thread that will use PrintQueue.AddJob to single threading.
printingThread.SetApartmentState(ApartmentState.STA);
printingThread.Start();
printingThread.Join();
}
}
public void Print_XPXFile(PrintQueue pQueue, String FilePath)
{
// Create print server and print queue.
bool fastCopy = pQueue.IsXpsDevice;
FileInfo file = new FileInfo(FilePath);
if (!file.Exists)
{
Console.WriteLine("There is no such file.");
}
else
{
Console.WriteLine("Adding {0} to {1} queue. share name : {2}", FilePath, pQueue.Name, pQueue.ShareName);
try
{
// Print the Xps file while providing XPS validation and progress notifications.
PrintSystemJobInfo xpsPrintJob = pQueue.AddJob(file.Name, FilePath, fastCopy);
Console.WriteLine("Done adding.");
}
catch (PrintJobException e)
{
Console.WriteLine("\n\t{0} could not be added to the print queue.", file.Name);
if (e.InnerException.Message == "File contains corrupted data.")
{
Console.WriteLine("\tIt is not a valid XPS file."); // Use the isXPS Conformance Tool to debug it.
}
else
{
Console.WriteLine("\tmessage : {0}", e.InnerException.Message);
}
}
}
}
のMicrosoft XPSドキュメントライターに印刷する、Microsoftはそれが正常に動作など、PDFに印刷します。
すべてで問題なく動作しています。XPS based printers
私はさらにXPSサンプルプリンタドライバをインストールし、この主張を確認する仮想ローカルプリンタを追加し、それが期待通りに機能するようにしました。
非xpsベースのプリンタの場合、実際にはAddJob機能でスタックされます。どちらの例外もスローされず、次のステートメントに移動もしません。
this msdnリソースに基づいてコードを作成しました。
原因と解決方法は何ですか?
すべての考えを歓迎します。
Thanx!私はまだ根本的な原因を知る必要があります。私はこの答えを今受け入れます。根本的な原因について他の誰かが投稿したら、私はそれらを受け入れます。 –