ShellExecute を使用して Windows サービスから pdf、ppt、および word ドキュメントを印刷しようとしています。
Process printingProcess = new Process
{
StartInfo =
{
FileName = filePath,
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true,
UseShellExecute = true,
Verb = "Print"
}
};
printingProcess.Start();
これはほとんどの場合に機能します。しかし、破損している Word 文書の場合、Process.Start メソッドは完了せず、サービスがハングします。
基本的に、Word は "bad document! repair" ダイアログをポップアップします。私は、単語が適切に再生されていないことをサービスが識別し、プロセスを強制終了して、キュー内の次のドキュメントに進むようにしたいと考えています。
私は何をすべきか?
[アップデート]
皆さん、問題を再現するコードは次のとおりです。
static void Main(string[] args)
{
string filePath = @"d:\corruptdocument.docx";
PrintDocument(filePath);
Console.WriteLine("Completed!");
Console.ReadKey();
}
private static void PrintDocument(string filePath)
{
Process printingProcess = new Process
{
StartInfo =
{
FileName = filePath,
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true,
UseShellExecute = true,
Verb = "Print"
}
};
using (printingProcess)
{
Console.WriteLine("Starting process...");
printingProcess.Start();
Console.WriteLine("Completed start...");
}
}
そして、ここにスクリーンショットがあります:http://twitpic.com/23jwor