By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,448 Members | 1,338 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,448 IT Pros & Developers. It's quick & easy.

Help need with POSTMESSAGE function in C#

P: n/a
(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
Share this Question
Share on Google+
1 Reply


P: n/a
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.