开发者

Equivalent of PosthreadMessage

开发者 https://www.devze.com 2023-01-12 21:16 出处:网络
Does .Net has an equivalent for Post开发者_运维技巧hreadMessage? We presently use a List (for keeping the items), a lock (protecting the list) and an event (to notify the consumer thread that an item

Does .Net has an equivalent for Post开发者_运维技巧hreadMessage?

We presently use a List (for keeping the items), a lock (protecting the list) and an event (to notify the consumer thread that an item has been added to the list) for the same functionality.

Is there any optimized way for implementing this?


There are some concurrent collections in .NET 4.0 (System.Collections.Concurrent) that perhaps you could use instead of rolling your own thread-safe data structure? I'm not sure what your requirements are, and I'm not sure how your wanting to optimize your container has anything to do with making it equivalent to PostThreadMessage. If you want, you can always use Managed C++ to expose PostThreadMessage to your .NET application. Or you can use PInvoke to call it from your app as well.


Doesn't look like there's much room for optimization here, unless you want to design it as single-threaded to avoid the context switch. This may anyway be preferred, from program logic point of view.

0

精彩评论

暂无评论...
验证码 换一张
取 消