如何强制Thread.Abort()中止? [英] how to force Thread.Abort() to Abort ?

查看:86
本文介绍了如何强制Thread.Abort()中止?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在使用COM互操作从我的.net应用程序调用MS word。如果word弹出一个

对话框,我的线程显然会挂起,直到对话框被回答。


这就是问题:因为应用程序正在运行在服务器上,没有人在那里回答对话框,所以我有另一个线程在

上调用Abort()在操作没有的情况下第一个线程在一定时间内完成




不幸的是,虽然对Thread.Abort()的调用有效,但对话框保持不变/>
up和随后的Thread.Join()挂起,直到对话框被取消。


这种行为有什么办法吗?这不会经常发生

所以我不在乎效率如何低,但它必须在无人值守的

服务器上运行所以我不能让我的应用永远陷入困境。


TIA


Andy

Hi,

I am using COM interop to invoke MS word from my .net app. If word pops up a
dialog box, my thread obviously hangs until the dialog is answered.

Here''s the problem: because the app is running on a server, there is nobody
there to answer the dialog, so I have another thread that calls Abort() on
the first thread in the event that the operation doesn''t complete within a
certain amount of time.

Unfortunately, whilst the call to Thread.Abort() works, the dialog box stays
up and the subsequent Thread.Join() hangs until the dialog is cancelled.

Is there any way round this behaviour? This isn''t going to happen very often
so I don''t care how inefficient it is, but it''s got to run on an unattended
server so I can''t afford to have my app get stuck forever.

TIA

Andy

推荐答案

中止实际上并没有被传递到托管线程,直到它从非托管调用返回
。没有办法绕过那个

的行为。


您可以尝试在单独的appdomain中运行互操作,然后

卸载appdomain而不是使用abort。我已经观察到CLR

会在卸载

应用程序域时更加长时间卸载冻结线程,然后再调用abort.


另一个选择是在一个完全独立的过程中运行它,然后卸载

过程。您可以在进程之间使用远程处理来在主进程和帮助程序进程之间来回发送数据。


简而言之,没有好处关闭在非托管

电话中冻结的线程的方法。


" Andy Fish" < AJ **** @ blueyonder.co.uk>在消息中写道

新闻:uI ************** @ TK2MSFTNGP09.phx.gbl ...
The abort does not actually get delivered to the managed thread until it
returns from the unmanaged call. There is no way to get around that
behavior.

You could try running the interop call in a separate appdomain, and then
unload the appdomain instead of using an abort. I''ve observed that the CLR
will go to greater lengths to unload frozen threads when unloading an
appdomain then when you simply call abort.

Another option is to run it in a totally separate process and then unload
the process. You could use remoting between processes to send data
back-and-forth between the main process and the helper process.

In short, there is no good way to shutdown a thread frozen in an unmanaged
call.

"Andy Fish" <aj****@blueyonder.co.uk> wrote in message
news:uI**************@TK2MSFTNGP09.phx.gbl...

我正在使用COM互操作从我的.net应用程序中调用MS word。如果弹出单词
一个对话框,我的线程显然会挂起,直到对话框被回答。

这就是问题:因为应用程序在服务器上运行,所以有 Abort(),如果操作在一定时间内没有完成。<不幸的是,虽然对Thread.Abort()的调用有效,但对话框
保持不变,后续的Thread.Join()会挂起,直到取消对话框为止。

这种行为有什么办法吗?这不会经常发生,所以我不在乎效率有多低,但它必须在无人值守的服务器上运行,所以我买不起让我的应用永远陷入困境。

TIA

Andy
Hi,

I am using COM interop to invoke MS word from my .net app. If word pops up
a dialog box, my thread obviously hangs until the dialog is answered.

Here''s the problem: because the app is running on a server, there is
nobody there to answer the dialog, so I have another thread that calls
Abort() on the first thread in the event that the operation doesn''t
complete within a certain amount of time.

Unfortunately, whilst the call to Thread.Abort() works, the dialog box
stays up and the subsequent Thread.Join() hangs until the dialog is
cancelled.

Is there any way round this behaviour? This isn''t going to happen very
often so I don''t care how inefficient it is, but it''s got to run on an
unattended server so I can''t afford to have my app get stuck forever.

TIA

Andy



用户服务器上的对话框表示设计或在预期环境之外使用

组件。你们两个中哪一个可以修复?b / b
-

问候,

Alvin Bruney


无耻的作者插件

带有.NET的Microsoft Office Web Components黑皮书
http://tinyurl.com/27cok

" Andy Fish" < AJ **** @ blueyonder.co.uk>在消息中写道

新闻:uI ************** @ TK2MSFTNGP09.phx.gbl ...
A user dialog on a server indicates either poor design or usage of a
component outside of its intended environment. Which of the two can you
repair?

--
Regards,
Alvin Bruney

Shameless Author plug
The Microsoft Office Web Components Black Book with .NET
http://tinyurl.com/27cok
"Andy Fish" <aj****@blueyonder.co.uk> wrote in message
news:uI**************@TK2MSFTNGP09.phx.gbl...

我正在使用COM互操作从我的.net应用程序中调用MS word。如果弹出单词
一个对话框,我的线程显然会挂起,直到对话框被回答。

这就是问题:因为应用程序在服务器上运行,所以有 Abort(),如果操作在一定时间内没有完成。<不幸的是,虽然对Thread.Abort()的调用有效,但对话框
保持不变,后续的Thread.Join()会挂起,直到取消对话框为止。

这种行为有什么办法吗?这不会经常发生,所以我不在乎效率有多低,但它必须在无人值守的服务器上运行,所以我买不起我的应用程序永远被卡住了。

TIA

Andy
Hi,

I am using COM interop to invoke MS word from my .net app. If word pops up
a dialog box, my thread obviously hangs until the dialog is answered.

Here''s the problem: because the app is running on a server, there is
nobody there to answer the dialog, so I have another thread that calls
Abort() on the first thread in the event that the operation doesn''t
complete within a certain amount of time.

Unfortunately, whilst the call to Thread.Abort() works, the dialog box
stays up and the subsequent Thread.Join() hangs until the dialog is
cancelled.

Is there any way round this behaviour? This isn''t going to happen very
often so I don''t care how inefficient it is, but it''s got to run on an
unattended server so I can''t afford to have my app get stuck forever.

TIA

Andy



如果你的服务在没有桌面交互的情况下运行启用后,解决此问题是不可能的。
。如果您的服务与桌面交互运行

启用(它不应该)您可以尝试使用

SendInput模拟键盘输入(您必须确保对话框获得焦点) ),或者你可以尝试

获取Dialog的Window句柄并使用SendMessage模拟

按键。问题当然是实际上显示的是什么对话框?
显示了什么?,你不会在任何可能的对话框上按OK,不是吗?


这是你不应该尝试自动化办公室

申请的众多原因之一。 (或任何其他交互式应用程序)在服务器上。


Willy。


" Andy Fish" < AJ **** @ blueyonder.co.uk>在消息中写道

新闻:uI ************** @ TK2MSFTNGP09.phx.gbl ...
If your service runs without "desktop interaction" enabled, it''s impossible
to get around this issue. If your service runs with desktop interaction
enabled (it shouldn''t) you can try to simulate Keyboard input using
SendInput (you have to make sure the dialog got focus), or you can try to
get the Window handle of the Dialog and use SendMessage to simulate a
key-press. The problem of course is "what dialog is there actually
displayed?", you won''t press OK on any possible dialog don''t you?

This is one of the many reasons you shouldn''t try to automate "Office
applications" (or any other interactive application) on a server.

Willy.

"Andy Fish" <aj****@blueyonder.co.uk> wrote in message
news:uI**************@TK2MSFTNGP09.phx.gbl...

我正在使用COM互操作从我的.net应用程序中调用MS word。如果弹出单词
一个对话框,我的线程显然会挂起,直到对话框被回答。

这就是问题:因为应用程序在服务器上运行,所以有 Abort(),如果操作在一定时间内没有完成。<不幸的是,虽然对Thread.Abort()的调用有效,但对话框
保持不变,后续的Thread.Join()会挂起,直到取消对话框为止。

这种行为有什么办法吗?这不会经常发生,所以我不在乎效率有多低,但它必须在无人值守的服务器上运行,所以我买不起让我的应用永远陷入困境。

TIA

Andy
Hi,

I am using COM interop to invoke MS word from my .net app. If word pops up
a dialog box, my thread obviously hangs until the dialog is answered.

Here''s the problem: because the app is running on a server, there is
nobody there to answer the dialog, so I have another thread that calls
Abort() on the first thread in the event that the operation doesn''t
complete within a certain amount of time.

Unfortunately, whilst the call to Thread.Abort() works, the dialog box
stays up and the subsequent Thread.Join() hangs until the dialog is
cancelled.

Is there any way round this behaviour? This isn''t going to happen very
often so I don''t care how inefficient it is, but it''s got to run on an
unattended server so I can''t afford to have my app get stuck forever.

TIA

Andy



这篇关于如何强制Thread.Abort()中止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆