473,396 Members | 2,109 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,396 software developers and data experts.

How do I do a SendMessage like operation in C#

In VC++ When I wanted to send a message to a window from a worker
thread I would use SendMessage. Events only work Semi-well in C#
becuase certain GUI operations require they run in the same thread that
the window exists in. Such as displaying a balloon on the tray. Does
anyone know a good way to do this?

Jan 19 '06 #1
2 1159
In order to make a call to the thread that the UI is running on, you can
call the Invoke method on a control that was created on that thread. This
will allow you to pass a delegate that will get invoked on the UI thread, as
well as the parameters to pass to it.

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

<ch***************@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
In VC++ When I wanted to send a message to a window from a worker
thread I would use SendMessage. Events only work Semi-well in C#
becuase certain GUI operations require they run in the same thread that
the window exists in. Such as displaying a balloon on the tray. Does
anyone know a good way to do this?

Jan 19 '06 #2
Hi,

I've actually written an article about this a while back. http://www.lowendahl.net/content.asp...pContent=csa31
It shows a pattern you can use to ensure that your events execute on the
correct thread.

--
Patrik Löwendahl [C# MVP]
http://www.lowendahl.net

In order to make a call to the thread that the UI is running on,
you can call the Invoke method on a control that was created on that
thread. This will allow you to pass a delegate that will get invoked
on the UI thread, as well as the parameters to pass to it.

Hope this helps.

<ch***************@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
In VC++ When I wanted to send a message to a window from a worker
thread I would use SendMessage. Events only work Semi-well in C#
becuase certain GUI operations require they run in the same thread
that the window exists in. Such as displaying a balloon on the tray.
Does anyone know a good way to do this?

Jan 19 '06 #3

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

Similar topics

5
by: Mark Overstreet | last post by:
I am trying to click a button in another window and I have it's hWnd value so I was trying to use Send message. Here is my code but it doesn't work as expected... response =...
3
by: JSK | last post by:
Hi, As any one worked in VB.NET and made use of Sendmessage API? The Issue I am running into is how to pass pointers of Data Structures (UDT) to the SendMessage. I starting looking at "IntPrt"...
0
by: SamSpade | last post by:
In my C# library I have many SendMessages like the following: public static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, ref PARAFORMAT2 pf2); I use this one like this:
3
by: Rob | last post by:
Hi all, I am having trouble converting the code below (found on http://vbnet.mvps.org/index.html?code/core/sendmessage.htm) into a format that will work using vb .NET. Can anyone have a look...
18
by: Lars Netzel | last post by:
Hello! Thanx to this newgroup I have finally, with the help of you guys, gotten this to work halfway.. but the final action is still not working, clicking the "Button2" thru SendMessage(). ...
4
by: Abubakar | last post by:
Hi, My application has a lot of threads which at some point call SendMessage api passing it the handle of the gui window. The calls r a lot. My question is that should I call the SendMessage api...
22
by: SQACSharp | last post by:
I'm trying to get the control name of an editbox in another window. The following code set the value "MyPassword" in the password EditBox but it fail to return the control name of the EditBox. ...
1
by: Necromis | last post by:
Ok, I have gotten my head around things better regarding SendMessage and FindWindow functions. However, I am running into an issue with my code still. The program I am working with is EXTRA! by...
5
by: michelqa | last post by:
Hi, I need to call a lot of different native SendMessage to retreive informations from non managed application. Some win32 messages use struct pointer for lparam....how to create and...
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
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
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?
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
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...

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.