468,296 Members | 1,328 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,296 developers. It's quick & easy.

Help need with POSTMESSAGE function in C#

(Type your message here)
I am writing an application that does lot of read/write's withcomputer's serial port. The application as a whole is workingfine.
Current Approach: I have a Timer that checks once every millisecond to see if there is any data avaialable to read at theserial port. If so then reads it. The serial port is openedwithout OVERLAPPING.

TRYING TO GET TO: I don't think polling serial port every millisecond is a good approach. I am thinking of creating a seperatethread that waits for data to come at the serial port. When thedata arrives, it should inform it to the main thread which ishandling the User Interface. For this, I am trying to use Win32API function POSTMESSAGE to post data to the main form window'smessage loop. I have overriden both PreProcessMessage() andWndProc() functions. But no use. I never get that message to themain thread. But no compilation errors. Am I doing somethingwrong here?? I don't want to use delegates, threadpool stuff.

Any suggestions would be highly appreciated.

Thank you all
--------------------------------
From: Srinivasa Ra

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>g7BHK7vZY0Se6YVC4wOoFw==</Id>
Nov 16 '05 #1
1 2252
Srinivasa,

Don't use the PostMessage routine. Rather, make a control from the UI
thread available to the worker thread. On the worker thread, you call
Invoke, passing a delegate, and the parameters that are to be passed to the
delegate.

Calling Invoke on the control with the delegate causes the delegate to
be invoked on the UI thread. So basically, you would write a function which
would update your UI, and then create a delegate that will wrap the function
and pass that to Invoke from your worker thread.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Srinivasa Ra via .NET 247" <an*******@dotnet247.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
(Type your message here)
I am writing an application that does lot of read/write's with computer's
serial port. The application as a whole is working fine.
Current Approach: I have a Timer that checks once every milli second to see
if there is any data avaialable to read at the serial port. If so then reads
it. The serial port is opened without OVERLAPPING.

TRYING TO GET TO: I don't think polling serial port every milli second is a
good approach. I am thinking of creating a seperate thread that waits for
data to come at the serial port. When the data arrives, it should inform it
to the main thread which is handling the User Interface. For this, I am
trying to use Win32 API function POSTMESSAGE to post data to the main form
window's message loop. I have overriden both PreProcessMessage() and
WndProc() functions. But no use. I never get that message to the main
thread. But no compilation errors. Am I doing something wrong here?? I don't
want to use delegates, threadpool stuff.

Any suggestions would be highly appreciated.

Thank you all
--------------------------------
From: Srinivasa Ra

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>g7BHK7vZY0Se6YVC4wOoFw==</Id>
Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by ayiiq180 | last post: by
15 posts views Thread by James | last post: by
12 posts views Thread by Wilfried Mestdagh | last post: by
2 posts views Thread by Husam | last post: by
1 post views Thread by Michael D. Reed | last post: by
3 posts views Thread by knikkix | last post: by
2 posts views Thread by lgbjr | last post: by
21 posts views Thread by one2001boy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.