473,748 Members | 2,274 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 PreProcessMessa ge() 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>g7BHK7vZY0S e6YVC4wOoFw==</Id>
Nov 16 '05 #1
1 2687
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.co m

"Srinivasa Ra via .NET 247" <an*******@dotn et247.com> wrote in message
news:%2******** ********@tk2msf tngp13.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 PreProcessMessa ge() 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>g7BHK7vZY0S e6YVC4wOoFw==</Id>
Nov 16 '05 #2

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

Similar topics

1
3411
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 place(like taskbar),it cant work,why?help me. this is the hook: // HookDll.cpp : Defines the initialization routines for the DLL. // #include "stdafx.h" #include "HookDll.h"
15
8452
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 System.Windows.Forms; using System.Runtime.InteropServices; namespace mynamespace
12
7197
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 illegal cross thread operation if posting a message. Is this a bug introduced in latest version of dotnet ? It is very legal to use postmessage because the message will execute in context of the thread the one was posted to. Same with...
6
4771
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 WndProc function located into the VB.NET code. Until the code was VB6/C code, they was OK. Now the VB WndProc receives the startup message correctly
2
1230
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 lpClassName As String, ByVal lpWindowName As String) As Integer ' End Function
1
1977
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 statement. Help.ShowHelp(Parent:=Me, url:=Me.HELP_URL_PRE & Me.myWorker.HelpFile) How do I get it to go away when the program exits? Now when I quit the program that I called it form the help file is sill displayed. Is there a way to get a handle...
3
9468
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 Button1.Click AppGlobals.SetHandles(Me.Handle.ToInt64()) Call OpenModel() End Sub
2
4657
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 This" support by using the ? button in the form header, but..... I don't want to give up the Min and Max buttons. So, If I create my own ? button on the form somewhere, what do I put in the Click Event? I never used VB6, but in all of my...
21
6894
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
8831
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9552
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9376
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9326
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9249
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8245
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4607
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3315
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.