Я пытаюсь распечатать документы pdf, ppt и word из моей службы Windows, используя ShellExecute.
Process printingProcess = new Process
{
StartInfo =
{
FileName = filePath,
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true,
UseShellExecute = true,
Verb = "Print"
}
};
printingProcess.Start();
Это работает в большинстве случаев. Но для документов Word, которые повреждены, метод Process.Start никогда не завершается, и служба зависает.
В основном, слово всплывает в диалоге "плохой документ! Ремонт". Я хочу, чтобы служба определила, что это слово не играет хорошо, и убила процесс, и приступила к следующему документу в своей очереди.
Что мне делать?
[ОБНОВЛЕНИЕ]
Ребята, вот код для воспроизведения проблемы:
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