PostMessage不安全吗? [英] PostMessage unsafe?

查看:109
本文介绍了PostMessage不安全吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁可以解释为什么PostMessage到Windows窗体

被认为是不安全的并引发InvalidOperationException?

我可以摆脱那个设置CheckForIllegalCrossThreadCalls

为假,一切正常。我还是觉得有点不好意思。


谢尔盖

Can anyone explain why PostMessage to a Windows Form
is considered unsafe and raises InvalidOperationException?
I can get rid of that setting CheckForIllegalCrossThreadCalls
to false and everything works just fine. Still I feel somewhat
uncomfortable.

Sergei

推荐答案

谢尔盖,


这个方法是什么? AFAIK Widnows Forms并没有提供这样的方法。

你在谈论可以通过PInvoke使用的API方法吗?如果你是
那么这就是你的问题的答案,为什么它不安全。


MSDN的简要跟踪告诉我有
WindowsCE。这是你要求的吗?

-


Stoitcho Goutsev(100)


" ;谢尔盖" < se **** @ nospam.summertime.mtu-net.ruwrote in message

news:%2 **************** @ TK2MSFTNGP02。 phx.gbl ...
Sergei,

What is this method? AFAIK Widnows Forms doesn''t provide such a method. Are
you talking about the API method that can be used through PInvoke? If you
are then this is the answer of your question why it is unsafe.

Brief cosulting with the MSDN tells me that there is PostMessage for
WindowsCE. Is it the one that you are asking for?
--

Stoitcho Goutsev (100)

"Sergei" <se****@nospam.summertime.mtu-net.ruwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...

任何人都可以解释为什么PostMessage到Windows窗体

被认为是不安全的并引发InvalidOperationException?

我可以摆脱那个设置CheckForIllegalCrossThreadCalls

为假,一切正常。我还是觉得有点不好意思。


谢尔盖
Can anyone explain why PostMessage to a Windows Form
is considered unsafe and raises InvalidOperationException?
I can get rid of that setting CheckForIllegalCrossThreadCalls
to false and everything works just fine. Still I feel somewhat
uncomfortable.

Sergei





谢尔盖 < se **** @ nospam.summertime.mtu-net.ruwrote in message

news:%2 **************** @ TK2MSFTNGP02。 phx.gbl ...

|任何人都可以解释为什么PostMessage到Windows窗体

|被认为是不安全的并引发InvalidOperationException?

|我可以摆脱那个设置CheckForIllegalCrossThreadCalls

|假的,一切都很好。我还是觉得有点

|不舒服。

|

|谢尔盖


IMO这不是由PostMessage API调用引起的,但我所知道的是

你以某种方式触摸来自UI线程以外的线程的UI。

这是你不应该做的事情,当你需要访问UI元素时

来自另一个线程,你必须编组使用Control.Invoke或BeginInvoke方法之一调用'控件'拥有

线程。


Willy。


"Sergei" <se****@nospam.summertime.mtu-net.ruwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
| Can anyone explain why PostMessage to a Windows Form
| is considered unsafe and raises InvalidOperationException?
| I can get rid of that setting CheckForIllegalCrossThreadCalls
| to false and everything works just fine. Still I feel somewhat
| uncomfortable.
|
| Sergei

IMO this is not caused by the PostMessage API call, but what I know is that
you are somehow "touching" the UI from a thread other than the UI thread.
This is something you should not do, when you need to access UI elements
from another thread, you have to marshal the call''s to the control''s owning
thread using one of the Control.Invoke or BeginInvoke methods.

Willy.


Stoitcho Goutsev(100)写道:
Stoitcho Goutsev (100) wrote:

谢尔盖,


这个方法是什么? AFAIK Widnows Forms并没有提供这样的方法。

你在谈论可以通过PInvoke使用的API方法吗?如果你是
那么这就是你的问题的答案,为什么它不安全。


MSDN的简要跟踪告诉我有
WindowsCE。这是你要求的吗?
Sergei,

What is this method? AFAIK Widnows Forms doesn''t provide such a method. Are
you talking about the API method that can be used through PInvoke? If you
are then this is the answer of your question why it is unsafe.

Brief cosulting with the MSDN tells me that there is PostMessage for
WindowsCE. Is it the one that you are asking for?



不,这是API,我从另一个UI线程调用它。

我仍​​然不明白为什么它线程不安全。

我总是使用PostMessage进行安全的线程间通信,现在它显示它不是那么安全。


谢尔盖

No, it''s API and I call it from another the UI thread.
Still I don''t understand why it is thread unsafe.
I''ve always used PostMessage for safe interthread communication, now it
appears it is not that safe.

Sergei


这篇关于PostMessage不安全吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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