I am creating a thread via "new Thread(new ThreadStart(p.T hreadProc))", is it
safe for ThreadProc to use GetMessage/TranslateMessag e/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 PostThreadMessa ge in
unmanaged code).
Thanks. 4 2022
Benny <bl**@newsgroup .nospam> wrote: I am creating a thread via "new Thread(new ThreadStart(p.T hreadProc))", is it safe for ThreadProc to use GetMessage/TranslateMessag e/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 PostThreadMessa ge 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.co m> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
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.
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 "interestin g" threading.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
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/TranslateMessag e/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 PostThreadMessa ge 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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 fail if the event is
emptied of all methods between the two statements, implying that some sort
of synchronization between this and removals from EventName is needed. The
other problem is that if an event with a set of delegates is in the process...
|
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.
Williams & D. Lane".
So I try to use
|
by: JR |
last post by:
Hi folks,
How can I implement the following in C#?
while(AppExitFlag == false)
{
if(AppPausedFlag == true)
{
GetMessage();
// Process messages.
|
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 System.Windows.Forms.Application.DoEvents from within a
dll, but it isn't allowed. I don't want to link the dll to our WinForm exe
which can call DoEvents.
Is there some way to call DoEvents from within a dll?
Thanks.
|
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 treeviews are cleared, etc)....
If their clicks make the code work synchronously, evertything is fine, it
would catch up with itself. The problem is that as soon as a webservice call
is made, the system seems to perform a doevents, i say this...
| |
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 hell of a time with it...
The following comes from phpinfo():
PHP Version: 5.1.2
mysql Client API version: 5.0.18
mysqli Client API version: 5.0.18
|
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 C:\php\PEAR\lib\MDB2.php on line
1921"
My code is a simple submit processing form for a login page:
<?php
|
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.');
var dealinit = new keybEdit('abcdefghijklmnopqurstuvwxyz01234567890 ','Alpha-numeric input only.');
var dealername = new keybEdit('abcdefghijklmnopqurstuvwxyz ','Alphabets input only.');
var rank = new...
|
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 terminating the thread. Calling this method
usually terminates the thread."
I've had a long discussion with someone on not to use the mentioned
method unless under the most extreme cases. I believe that it's
|
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,...
|
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,...
| |
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...
|
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...
|
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...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |