worker thread vs main thread? 
Author Message
 worker thread vs main thread?

Is there an easy way to determine if I'm in a worker thread vs the main
thread? I tried calling:

if( AfxGetMainWnd() )

expecting that it would return NULL if it was the worker thread, based on an
article by NewComer on CodeProject. However, it didn't return null in the
worker thread. Any ideas?



Sun, 31 Oct 2004 07:32:10 GMT  
 worker thread vs main thread?
DWORD globalMainThreadID;

int WinMain(...) {
    globalMainThreadID = GetCurrentThreadId();
   // Spawn worker threads and run app...

Quote:
}

void MyFunctionThatCouldBeCalledFromAnyThread() {
    if (GetCurrentThreadId() == globalMainThreadID) {
        // I'm in the main thread.
    }
    else {
        // I'm in a worker thread.
    }

Quote:
}

// -Sean


Sun, 31 Oct 2004 08:26:45 GMT  
 worker thread vs main thread?
Sean,

Thank you so much.  That did the trick.

Gunnar


Quote:
> DWORD globalMainThreadID;

> int WinMain(...) {
>     globalMainThreadID = GetCurrentThreadId();
>    // Spawn worker threads and run app...
> }

> void MyFunctionThatCouldBeCalledFromAnyThread() {
>     if (GetCurrentThreadId() == globalMainThreadID) {
>         // I'm in the main thread.
>     }
>     else {
>         // I'm in a worker thread.
>     }
> }

> // -Sean



Sun, 31 Oct 2004 18:19:29 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. main GUI thread -vs- Main Frame Thread

2. Handling events from a worker thread in the main thread

3. component in main threads used in worker threads

4. How to Send messages from worker thread to main thread

5. Synchronization problem between main thread and worker thread

6. Posting a message from a worker thread to the main app thread

7. Posting messages to the main window from worker threads

8. COM Threading Model for ISAPI Worker Threads

9. Exe server threading model - events from worker thread question

10. how do i create thread safe worker thread

11. How can i terminate a Worker Thread during a Thread is running?Thank

12. UI Thread better than Worker thread for speed?

 

 
Powered by phpBB® Forum Software