?
Solved

How to know which thread executes a certain windows message Q

Posted on 2003-11-12
3
Medium Priority
?
203 Views
Last Modified: 2013-11-20
I have created an UI thread and another class (say X) inherriting CFrameWnd, now i miss equating my thread's m_pMainWnd variable to my newly created instance of X. I went forward with posting messages to X's Q and it is working. The query is in the context of which thread, the main application one or my UI thread, are these posted messages getting executed.
0
Comment
Question by:shell_gem
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 11

Accepted Solution

by:
KurtVon earned 400 total points
ID: 9731740
Well, it is easy to see which in the debugger.  Put a breakpoint in the message handler and then go to the "Threads" window when it breaks.  In Visual Studio 6.0 go to Debug|Thread... in the menu.  In Visual Studio .Net there is a "Threads" window in the same tab section as the call stack window.

Either way, you can see a list of all the threads executing and figure out which one is stopped in your function.

For the record, unless you are leaving some information out, the main application thread should be handling the messages.
0
 
LVL 13

Expert Comment

by:SteH
ID: 9731991
Normally you need to post the messages to your thread to be executed by that thread. And a UI thread needs a class to be used for excution:

m_pYourThread = (CYourThread*) AfxBeginThread (RUNTIME_CLASS(CYourThread),
        THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED, NULL);
is a way to start this thread. To post messages to it you use either the pointer to that thread:

m_pYourThread->PostThreadMessage (message, wParam, lParam);

or use the thread ID:

::PostThreadMessage (idThread, message, wParam, lParam)

Otherwise messages are posted to the main thread but might be handled by different windows.
0
 
LVL 9

Expert Comment

by:Priyesh
ID: 9737405
You can try a trace before your query statements.

like TRACE("Thread ID = %d, executing query xxx "\n", GetCurrentThreadId()) ;

so you know which thread does it.
0

Featured Post

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month13 days, 17 hours left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question