Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to effectively wait for a thread to complete in a dialog class?

How to effectively wait for a thread to complete in a dialog class?

Scheduled Pinned Locked Moved C / C++ / MFC
c++hardwaretutorialquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kiran Satish
    wrote on last edited by
    #1

    I have a MFC dialog application with multiple child dialogs inside a main dialog and then a few normal classes controlling a camera and other hardware. I have a thread in camera class that is always active and waits for couple of events to do further processing within the thread. One of the events is a manual event and the other one auto event. The manual event keeps running as soon as the application is launched. But when the user pressed a button on one of the child dialogs, I would like to Set the auto event, for this within the button even handler of the child dialog, I call ResetEvent() on the camera thread manual event, wait for sometime using ::WaitForSingleObject command and then call SetEvent() on the camera thread auto event. But not matter how much time I wait in the even thandler, the SetEvent executes only when I am out of the button's event handler. Ideally I would like to wait for another event (using WaitForSingleObject) that is Set by the camera thread after its done with the autoevent process.

    // All events are global handles
    //Camera class
    //thread function
    {
    event[1] = manual event;
    event[2] = auto event;
    event[3] = auto event done event;

    switch(Waitformultipleobject(event[3]))
    {
    case manual event:
    // keep doing some process until the manual event is reset
    break;
    case auto event:
    // perform the process
    Set (auto event done event);
    break;}
    }
    }

    //Child dialog class
    button event handler
    {
    Reset(manual event)
    Set(auto event)
    WaitForSingleObject(auto event done event, ms);
    }

    Any tips/suggestions on how to achieve this?

    PKNT

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups