473,394 Members | 1,724 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,394 software developers and data experts.

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 2622
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: ayiiq180 | last post by:
my hook already in a dll and the handle is shared,but the hook cant work well,when i run the application,My mouse click the application's view,the hook work well,but when i click the other...
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...
6
by: SM | last post by:
Hello group, i'm converting a VB6 application for .NET Framework. The application depends on a DLL written in standard C. The C DLL code creates an invisible window with CreateWindow() with the...
2
by: Husam | last post by:
Hi EveryBody: I have the following code which just helpfull with Notepad: Code: <DllImport("user32", CharSet:=CharSet.Auto, SetLastError:=True)> _ Public Shared Function FindWindow(ByVal...
1
by: Michael D. Reed | last post by:
I am using the help class to display a simple help file. I generated the help file using Word and saving it as a single page Web page (.mht extension). I show the help file with the following...
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...
2
by: lgbjr | last post by:
hi All, I'm building the help system for a VB.Net 2005 winform application (some tooltips and a HelpProvider, etc.). For the HelpProvider, there are controls that I would like to have "What's...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.