-3

我的 c# 应用程序在任务管理器中创建 winword 并从任务管理器正确关闭。但万一我的应用程序崩溃了,winword 仍然在任务管理器中打开,并且无法处理那些 word 文档。

所以在那种情况下,我想单独杀死那些由我的应用程序而不是全部创建的winword。

请帮助完成这个。

4

2 回答 2

1

When instances of winword.exe are created through interop, they'll have the string "/Automation -Embedding" included in the process command line.

So, if you want to manually kill only your interop winword processes, without killing any user-initiated instances of Microsoft Word, you can open up Mark Russinovich's free ProcessExplorer utility, right click on a line with winword.exe, choose "properties", and look at the command line (in the Image tab). If you see the /Automation switch, you'll know it's an interop process and you can kill it. Here's how the interop winword.exe will look in ProcessExplorer:

interop winword in Process Explorer

于 2012-09-06T21:05:16.900 回答
0

尝试以下操作:

try
{
    // open your word document
    // process your word document
}
catch
{
    // handle any errors (e.g. provide error messages
}
finally
{
    // close the word document properly
}

为了防止孤立的文字进程,您需要将打开的进程集中存储在应用程序中,并在关闭应用程序之前关闭所有剩余进程。此外,您可以注册未处理的错误事件,然后在发生这种情况时关闭所有进程。

在大多数情况下,如果您无法打开文档,则无法关闭文字处理,因为该文档可能会在“真实”单词实例中打开以进行编辑。

于 2012-09-04T08:50:36.793 回答