Thread: Thread help

  1. #1
    Registered User (TNT)'s Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    339

    Thread help

    Hi,

    I have a thread set up as follows:

    Code:
    hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) CheckingThreadProc, mailsettings, 0, &dwThreadId);
    						
    WaitForSingleObject(hThread, INFINITE);
    
    CloseHandle(hThread);
    Now the thread takes about 5 seconds to execute, which is a problem because the WaitForSingleObject function pauses the program for a few seconds.

    Now if i dont call the WaitForSingleObject() function, is there any kind of function i can call to check if the thread is still active? Specifically code within WM_TIMER can only be executed if the thread has finished execution.

    And i need to do this without causing a program pause effect.

    Thanks
    Jack
    TNT
    You Can Stop Me, But You Cant Stop Us All

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Set a global flag just before you start the thread. The WM_TIMER code tests that flag and only executes the critical code if it's not set. Just before the thread functions ends, the last action it performs is to reset the flag.
    You don't even need thread synchronization for that.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User (TNT)'s Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    339
    EDIT: Thanks ive got it working now
    Last edited by (TNT); 07-07-2006 at 05:50 AM.
    TNT
    You Can Stop Me, But You Cant Stop Us All

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Thread Synchronization in Win32
    By passionate_guy in forum C Programming
    Replies: 0
    Last Post: 02-06-2006, 05:34 AM
  2. [code] Win32 Thread Object
    By Codeplug in forum Windows Programming
    Replies: 0
    Last Post: 06-03-2005, 03:55 PM
  3. Win32 Thread Object Model Revisted
    By Codeplug in forum Windows Programming
    Replies: 5
    Last Post: 12-15-2004, 08:50 AM
  4. Simple thread object model (my first post)
    By Codeplug in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2004, 11:34 PM
  5. Problem : Threads WILL NOT DIE!!
    By hanhao in forum C++ Programming
    Replies: 2
    Last Post: 04-16-2004, 01:37 PM