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

User defined mesage in C#?

When porting the Win32/MFC code to C#, I do not know how to deal with those
user defined windows messages. I just cannot cannot find an equivalent thing
in C#. Those messsages are so convenient in C/C++, especially when a thread
needs to inform the main GUI thread something, then continue its tasks:

ThreadFunc()
{
Doing something...
SendMessage(WM_USER+123,....);
Continue doing things....
}

What's the .NET way to accomplish this?

--
Eric
Apr 20 '07 #1
3 2558
I know I can use the backgroundWorker to accomplish this, but, I cannot
suspend/resume it as I can do with normal thread.

--
Eric
"Eric" wrote:
When porting the Win32/MFC code to C#, I do not know how to deal with those
user defined windows messages. I just cannot cannot find an equivalent thing
in C#. Those messsages are so convenient in C/C++, especially when a thread
needs to inform the main GUI thread something, then continue its tasks:

ThreadFunc()
{
Doing something...
SendMessage(WM_USER+123,....);
Continue doing things....
}

What's the .NET way to accomplish this?

--
Eric
Apr 20 '07 #2
On Fri, 20 Apr 2007 09:28:02 -0700, Eric <Er**@discussions.microsoft.com>
wrote:
When porting the Win32/MFC code to C#, I do not know how to deal with
those user defined windows messages. I just cannot cannot find an
equivalent thing in C#. Those messsages are so convenient in C/C++,
especially when a thread needs to inform the main GUI thread something,
then continue its tasks: [...]
Well, if you want to do a straight one-for-one port, .NET does have a way
for you to actually get at the window proc, overriding it so that you can
still process user-defined messages.

The .NET-friendly methods involve delegates and/or events (that is, .NET
events...not to be confused with Windows event handles). With a delegate,
you can use Control.Invoke() or Control.BeginInvoke() (which are like
SendMessage() and PostMessage(), respectively) to have a method run on the
GUI thread. This would be appropriate when you have a single method that
some thread needs to run and which needs to be executed on the GUI thread.

Alternatively, you can use an event to set up a "subscriber-based"
notification system. Events don't in and of themselves address the
cross-thread issue, and they still require the use of delegates. So the
reason you'd use an event is if you view your user-message as more of a
notification than a "do this work now" sort of thing. The difference is,
IMHO, more conceptual than practical.

Pete
Apr 20 '07 #3
Great information. The Control.Invoke() or Control.BeginInvoke() is just what
I want. Thanks!

--
Eric
"Peter Duniho" wrote:
On Fri, 20 Apr 2007 09:28:02 -0700, Eric <Er**@discussions.microsoft.com>
wrote:
When porting the Win32/MFC code to C#, I do not know how to deal with
those user defined windows messages. I just cannot cannot find an
equivalent thing in C#. Those messsages are so convenient in C/C++,
especially when a thread needs to inform the main GUI thread something,
then continue its tasks: [...]

Well, if you want to do a straight one-for-one port, .NET does have a way
for you to actually get at the window proc, overriding it so that you can
still process user-defined messages.

The .NET-friendly methods involve delegates and/or events (that is, .NET
events...not to be confused with Windows event handles). With a delegate,
you can use Control.Invoke() or Control.BeginInvoke() (which are like
SendMessage() and PostMessage(), respectively) to have a method run on the
GUI thread. This would be appropriate when you have a single method that
some thread needs to run and which needs to be executed on the GUI thread.

Alternatively, you can use an event to set up a "subscriber-based"
notification system. Events don't in and of themselves address the
cross-thread issue, and they still require the use of delegates. So the
reason you'd use an event is if you view your user-message as more of a
notification than a "do this work now" sort of thing. The difference is,
IMHO, more conceptual than practical.

Pete
Apr 20 '07 #4

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

Similar topics

1
by: arabub | last post by:
I have an installation of Apache that apparently includes PHP (out of the box Redhat 9.0). If I make database calls to Postgresql, as what user is that call going to be made? The user that...
0
by: Shailesh | last post by:
Hello, I want to set up some USER DEFINED METRICS in 10g. The restriction with USER DEFINED METRICS, is the query (or function ) monitoring that metrics should return only 1 value. I want to...
13
by: dawatson833 | last post by:
I have several stored procedures with parameters that are defined with user defined data types. The time it takes to run the procedures can take 10 - 50 seconds depending on the procedure. If I...
0
by: Joel914 | last post by:
Using Visual Web Developer Express Beta 2 and C# Using Login control In Validation Section of properties it shows PasswordRequiredErrorMessage and one called UserNameRequiredErrorMessage ...
2
by: David Emme | last post by:
Access 97 I have a number of SELECT statements which contain references to user-defined VBA functions. These typically work as expected, but occasionally, on one user's machine or another,...
17
by: Steve R. Hastings | last post by:
I have been studying Python recently, and I read a comment on one web page that said something like "the people using Python for heavy math really wish they could define their own operators". The...
1
by: ohagna | last post by:
in oracle form devoloper i tray to connect but get this error mesage : error mesage NO ORA12636 please what that mean ? ?
3
by: gehegeradeaus | last post by:
Is there a way to prevent one user-account from logging in twice on the same system when using sessions? I also put the session of a user in a mysql database : CREATE TABLE `login_sessions` (...
3
by: John | last post by:
Hi. I have a number of batch jobs that are ran nightly on our Windows 2000 based Oracle 8.1.7 (soon to be 9i) server. I have these designed just right, so the Windows Scheduled Tasks runs them...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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.