什么是GetMessage的C#等价物???? [英] What is the C# equivalent of GetMessage ????

查看:140
本文介绍了什么是GetMessage的C#等价物????的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我想在线程之间传递消息,使用好的旧C ++,我会调用GetMessage / PostThreadMessage API,现在,我正在使用C#,我可以'找不到这些调用的任何等价物,任何想法如何在线程之间进行通信以及访问线程消息队列都将被评估...

-

Nadav http://www.ddevel.com

推荐答案

这些是用户界面API,而不是线程通信API。

" System.Windows.Forms.Control.Invoke"函数将它们包装成一个干净的,
面向对象的方式(消息循环包含在应用程序

类IIRC中)。

Don'不要将它们用于非UI线程之间的通信。使用管道,

sychnronization对象,锁,事件&为此目的的朋友。如果

任何人都必须在你的代码中找到一个错误,她肯定会赞赏这个错误!


Niki


" Nadav" <的Na *** @ discussions.microsoft.com>写在

新闻:37 ********************************** @ microsof t .com ...
These were user interface APIs, not thread communication APIs. The
"System.Windows.Forms.Control.Invoke" function wraps them in a clean,
object-oriented fashion (the message loop is wrapped in the Application
class IIRC).
Don''t use them for communication between non-UI threads. Use pipes,
sychnronization objects, locks, events & friends for that purpose. If
anybody will ever have to find a bug in your code, she will definitely
appreciate that!

Niki

"Nadav" <Na***@discussions.microsoft.com> wrote in
news:37**********************************@microsof t.com...


我想在线程之间传递消息,使用好的旧C ++我会调用GetMessage / PostThreadMessage API,现在,我正在使用C#而且我无法找到任何相同的这些调用,任何想法如何在线程之间进行通信并访问线程消息队列将是
appriciated ... -
Nadav
http://www.ddevel.com






您好Niki,感谢您的回复,但是,如果有相同的线程,我对您的回复我并不理解消息队列管理Win32 API,线程消息队列管理必须有一个.NET类,线程消息队列管理是线程间通信的基本特征,我发现很难相信.NET框架没有以这种方式支持线程间通信,仍然,我找不到任何等效的Win32消息队列等价物(例如, GetMessage,PostThreadMessage,...)。

-

Nadav
http://www.ddevel.com

" Niki Estner"写道:
Hi Niki, Thanks for your response, Still, I didn''t understand from your response if there is an equivalent for the threads message queue management Win32 API, there must be a .NET class for the threads message queue management, Thread message queue management is an elementary feature in inter thread communication and i find it hard to believe that the .NET framework doesn''t support the inter-thread communication in this way, Still, I couldn''t find any equivalent to the Win32 message queue equivalents ( e.g. GetMessage, PostThreadMessage, ... ).
--
Nadav
http://www.ddevel.com
"Niki Estner" wrote:
这些是用户界面API,而不是线程通信API。
System.Windows.Forms.Control.Invoke函数以一种干净的,面向对象的方式包装它们(消息循环包含在应用程序
类IIRC中)。
不要将它们用于非UI线程之间的通信。使用管道, sychnronization对象,锁,事件&为此目的的朋友。如果任何人都必须在你的代码中找到一个错误,她肯定会对此表示赞赏!

Niki

  Nadav" <的Na *** @ discussions.microsoft.com>在
新闻中写道:37 ********************************** @ microsof t.com .. 。
These were user interface APIs, not thread communication APIs. The
"System.Windows.Forms.Control.Invoke" function wraps them in a clean,
object-oriented fashion (the message loop is wrapped in the Application
class IIRC).
Don''t use them for communication between non-UI threads. Use pipes,
sychnronization objects, locks, events & friends for that purpose. If
anybody will ever have to find a bug in your code, she will definitely
appreciate that!

Niki

"Nadav" <Na***@discussions.microsoft.com> wrote in
news:37**********************************@microsof t.com...


我想在线程之间传递消息,使用好的旧C ++我会调用GetMessage / PostThreadMessage API,现在,我是使用C#和i
找不到这些调用的任何等价物,任何想法如何在线程之间进行通信并访问线程消息队列将是
Hi,

I am tring to pass messages between threads, using the good old C++ I
would call the GetMessage/PostThreadMessage APIs, Now, I am using C# and i
can''t find any equivalenty for these calls, any Idea how to communicate
between threads and access the threads message queue will be


appriciated ...


appriciated...

-
Nadav
http:// www .ddevel.com




Nadav< Na *** @ discussion.microsoft.com>写道:
Nadav <Na***@discussions.microsoft.com> wrote:
嗨Niki,感谢您的回复,尽管如此,我还是不明白您的回复是否有等效的线程消息队列
管理Win32 API ,必须有一个.NET类用于线程
消息队列管理,线程消息队列管理是线程间通信的基本功能,我觉得很难相信.NET框架不支持这种方式的线程间通信,但是,我找不到任何等同于Win32消息队列的等价物(例如GetMessage,PostThreadMessage,
。 ..)。
Hi Niki, Thanks for your response, Still, I didn''t understand from
your response if there is an equivalent for the threads message queue
management Win32 API, there must be a .NET class for the threads
message queue management, Thread message queue management is an
elementary feature in inter thread communication and i find it hard
to believe that the .NET framework doesn''t support the inter-thread
communication in this way, Still, I couldn''t find any equivalent to
the Win32 message queue equivalents ( e.g. GetMessage, PostThreadMessage,
... ).




Interthread通讯不应该使用Win32消息队列,除非

它与UI有关,我想 - 在这种情况下你可以使用Control.Invoke




对于没有UI控制或你不在哪里的其他情况

想要去UI线程,你可以轻松设置自己的消息

队列。



http://www.yoda.arachsys.com/csharp/...onitor.methods


这个队列的一个非常简单的例子。 (在实践中你会想要一个

的方式来阻止队列等。)


-

Jon Skeet - < sk *** @ pobox.com>
http:// www。 pobox.com/~skeet

如果回复小组,请不要给我发邮件



Interthread communication shouldn''t use the Win32 message queue unless
it''s UI-related, I thought - in which case you can use Control.Invoke
etc.

For other situations where there aren''t UI controls or where you don''t
want to go to the UI thread, you can easily set up your own message
queue.

See
http://www.yoda.arachsys.com/csharp/...onitor.methods

for a very simple example of such a queue. (In practice you''d want a
way of stopping the queue etc.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


这篇关于什么是GetMessage的C#等价物????的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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