473,473 Members | 2,277 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

is it safe to call GetMessage instead of calling DoEvents

I am creating a thread via "new Thread(new ThreadStart(p.ThreadProc))", is it
safe for ThreadProc to use GetMessage/TranslateMessage/DispatchMessage
instead of DoEvents?

What I would like to do is to have messages posted to ThreadProc and have
ThreadProc process those messages (similar to using PostThreadMessage in
unmanaged code).

Thanks.
Apr 26 '06 #1
4 2002
Benny <bl**@newsgroup.nospam> wrote:
I am creating a thread via "new Thread(new ThreadStart(p.ThreadProc))", is it
safe for ThreadProc to use GetMessage/TranslateMessage/DispatchMessage
instead of DoEvents?

What I would like to do is to have messages posted to ThreadProc and have
ThreadProc process those messages (similar to using PostThreadMessage in
unmanaged code).


I would suggest using a queue of work items. See
http://www.pobox.com/~skeet/csharp/t...eadlocks.shtml
about half way down for a sample producer/consumer queue.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 26 '06 #2
Jon,

Thanks for the reply. I will do what is recommended.

For my future reference, is it safe to call unmanaged message APIs instead
of doing DoEvents? Thanks.
Apr 26 '06 #3
Benny <bl**@newsgroup.nospam> wrote:
Thanks for the reply. I will do what is recommended.

For my future reference, is it safe to call unmanaged message APIs instead
of doing DoEvents? Thanks.


I wouldn't recommend using DoEvents in the first place. Can you use the
unmanaged APIs? Probably - very carefully. I would try to avoid doing
so though. I've certainly never needed them myself, and I've done a
certain amount of "interesting" threading.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 26 '06 #4
Hi blee,

Thanks for your post!

Based on my understanding, you want to know if calling unmanaged message
API in the worker thread is safe, if I misunderstand you, please feel free
to tell me.

I am not sure why you want to call the
GetMessage/TranslateMessage/DispatchMessage API in a worker thread,
normally, these 3 APIs are used to construct a message loop, so that any
Windows message post/send to the thread can be processed correctly.
Normally GUI thread will use these APIs, because GUI thread will create
Window in the thread, then OS code will generate the proper messages for
the window to the GUI thread. Because a worker thread does not have a GUI
window, it will not have any messages in the queue.

However, if you want to use the Message APIs in the worker thread, I did
not see the problem, we can manually create a similar message loop in the
worker thread, then the *client* thread can p/inoke PostThreadMessage to
post the *wake* message to the thread message queue to wake up the
GetMessage API. This should be a way of doing one way cross-thread
communication. However, this kind of task can be easily achieved through
other dedicated thread communication technologies.

Hope this helps!

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 27 '06 #5

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

Similar topics

0
by: Steven Brown | last post by:
I'm trying to figure out how to safely use .NET events/delegates in a thread-safe class. There are a couple problems. One is that the standard "if(EventName != null) EventName(...);" call can...
1
by: muelli75 | last post by:
Hi! Im getting insane by solving a problem .... I try to define a function which uses a code-snippet from another file. My base are the codes from the great book "WebDataBase-Book by H....
2
by: JR | last post by:
Hi folks, How can I implement the following in C#? while(AppExitFlag == false) { if(AppPausedFlag == true) { GetMessage(); // Process messages.
3
by: dotNETDavid | last post by:
We've broken our app into various assemblies. The WinForm assembly provides the user interface, other assemblies provide various I/O services. I'd like to be able to call...
0
by: Andrew Teece | last post by:
HELP! I am calling a webservice as a result of an event in an infragistics control (well, various controls). Problem is that if a user clicks around the GUI alot, then my code crashes (because...
0
by: IamtheEvster | last post by:
Hi All, I am currently using PHP 5 and MySQL 5, both on Fedora Core 5. I am unable to call a MySQL stored procedure that returns output parameters using mysql, mysqli, or PDO. I'm having a...
2
by: salvadorvp | last post by:
Hi, I have the following code that gives me this odd error message at a line of code inside the PEAR libraries: "Fatal error: Call to undefined function: MDB2_Driver_mssql::getMessage(). in...
3
by: shyamg | last post by:
hi all, This javascript is working IE but not working in FIreFox, validating text fields. var dealerid = new keybEdit('abcdefghijklmnopqurstuvwxyz01234567890 ','Alpha-numeric input only.'); ...
6
by: mehdi | last post by:
Hi folks, You know, the Thread class has got a method named Abort which according to the msdn: "Raises a ThreadAbortException in the thread on which it is invoked, to begin the process of...
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...
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...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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...
0
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 ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.