473,395 Members | 2,222 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Replacement for postmessage

Hi

I need a replace for postmessage.

Sometimes I would like to notify the Application thread of some action. For
example, one thread is reading buffers from a socket, pushing them on a
queue list and I need to notify the main thread that he can start poping
buffers from this queue.

in Win32 I would just use a simple PostMessage where Msg > WM_USER. How
can I do the same in .Net. I should work on the CF to.

kind regards

Alexander

Nov 16 '05 #1
5 4586
The best thing to use for this Producer/Consumer pattern would be to use the Monitor Wait and Pulse methods. The thread that should read issues a Wait and the producer thread (putting things on the queue issues a Pulse when something is available. Then the Waiting thread wakes up and reads the queue. Unfortunately these methods aren't available on the CF. So in that case, assuming your application thread is a windows forms based application, use the Control.Invoke method to marshal a call to the UI thread for it to read the queue.

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

Hi

I need a replace for postmessage.

Sometimes I would like to notify the Application thread of some action. For
example, one thread is reading buffers from a socket, pushing them on a
queue list and I need to notify the main thread that he can start poping
buffers from this queue.

in Win32 I would just use a simple PostMessage where Msg > WM_USER. How
can I do the same in .Net. I should work on the CF to.

kind regards

Alexander
Nov 16 '05 #2
Correct me if I'm wrong

I would implement a private Control inside my class and use the BeginInvoke
method to do my desired behaviour.
Do I need to call the EndInvoke method or can I just void the result
BeginInvoke returns?

Isn't their a better way, this seems ugly complex for a simple thing.

kind regards

Alexander
Nov 16 '05 #3
Hi,

thanks for your reply

The problem is that I don't want my main thread to block. Therefor Wait is
not an option for me.

Postmessage was perfect an I need something equally simple. :-)

Kind regards

Alexander

Nov 16 '05 #4
Alexander Muylaert wrote:
Correct me if I'm wrong

I would implement a private Control inside my class and use the BeginInvoke
method to do my desired behaviour.
The control must be visible (it must have a HWND assigned)
to be able to do that, AFAIK.

If you want to use the *same* pattern like in your old apps
(PostMessage), then you have to handle the async calls
from within your forms (that already support Invoke/BeginInvoke).
Do I need to call the EndInvoke method or can I just void the result
BeginInvoke returns?

Isn't their a better way, this seems ugly complex for a simple thing.


See Richard's answer. The "Consumer" may not be your UI thread.
It can be another thread that communicates with the UI using
Invoke/BeginInvoke.

bye
Rob
Nov 16 '05 #5
Thats also why I suggested Control.Invoke (which is CF friendly). This assumes your application thread is pumping messages of course (as does PostMessage) so the thread would have had to call Application.Run

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

Hi,

thanks for your reply

The problem is that I don't want my main thread to block. Therefor Wait is
not an option for me.

Postmessage was perfect an I need something equally simple. :-)

Kind regards

Alexander

Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Paul | last post by:
Hi all. Probably a quick one, I'm using PostMessage to send keys to an applicatoin but how do I convert the key string to a long values so that I can pass this to the wParam. The definition is...
15
by: James | last post by:
In my code I have a problem in abtaining a windows handle. I do not know the namespace to obtain the windows hanle. here is the code. using System; using System.Collections; using...
12
by: Wilfried Mestdagh | last post by:
Hi, Using P/Invoke I use PostMessage to send a message from one thread to another. I'm pretty sure this has already worked in dotnet. but I've upgraded version 2 few day ago. Now I have an...
2
by: Lenster | last post by:
When using PostMessage to post myself a message, the msg and wparam parameters somehow get swapped over. They are in the correct order when calling PostMessage but by the time wndproc handles the...
3
by: Max M. Power | last post by:
When I use the SendMessage API I can sucessfully send and receive a user defined message. When I use the PostMessage API I can NOT sucessfully send and receive the same user defined message. ...
11
by: seattleboatguy | last post by:
I am trying to send a message from a visual c++ user-thread to the main window, so the main window can update text on the window to reflect what the user-thread is doing. I have tried 2 different...
3
by: knikkix | last post by:
Hi, I created a form in VB.Net with only one button. This is the code in button click event Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles...
10
by: Sergei | last post by:
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...
21
by: one2001boy | last post by:
PostMessage() function returns ERROR_NOT_ENOUGH_QUOTA after running in a loop for 700 times, but the disk space and memory are still big enough. any suggestion to resolve this problem? thanks.
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.