threads
-
Is there any Macro that can be used to know if the function that is running is called from a worker-thread or the main program? It is needed to know without use any addictional static global variable or addictional parameter to the function. thanks
Russell
-
Is there any Macro that can be used to know if the function that is running is called from a worker-thread or the main program? It is needed to know without use any addictional static global variable or addictional parameter to the function. thanks
Russell
-
This looks the solution:
if( AfxGetMainWnd()==NULL ){
// Thread specialization
}else{
// Main program specialization
}Any comment will be wellcome
Russell
May be you can use something like this... DWORD dwMainThreadId = 0; DWORD dwProcessId = 0; dwMainThreadId = GetWindowThreadProcessId( hMainWnd, &dwProcessId); if( dwMainThreadId == GetCurrentThreadId() ) { //Main Thread } else { //Thread specialization code } I have not tested this snippet.
-
May be you can use something like this... DWORD dwMainThreadId = 0; DWORD dwProcessId = 0; dwMainThreadId = GetWindowThreadProcessId( hMainWnd, &dwProcessId); if( dwMainThreadId == GetCurrentThreadId() ) { //Main Thread } else { //Thread specialization code } I have not tested this snippet.
-
Yes! your solution looks work better then mine
inline BOOL IsThisAThread(){
return GetCurrentThreadId()==GetWindowThreadProcessId(AfxGetMainWnd()->GetSafeHwnd(), NULL);
}thanks
Russell
*Edit* Never mind - that error doesn't occur :) Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
modified on Tuesday, September 23, 2008 4:56 PM
-
*Edit* Never mind - that error doesn't occur :) Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
modified on Tuesday, September 23, 2008 4:56 PM
yes, you are right....but as you suggested it is better in this way, thanks
inline BOOL IsThisAThread(){
CWnd* pMainWnd=AfxGetMainWnd();
if(! pMainWnd) return TRUE;
return GetCurrentThreadId()!=GetWindowThreadProcessId(pMainWnd->GetSafeHwnd(), NULL);
}
Russell