Thread: pointer to main thread from worker thread?

  1. #1
    Registered User
    Join Date
    Oct 2005

    pointer to main thread from worker thread?

    I create an MFC application in .net

    which create the appclass, and the dlg class
    i then create a generic thread class so i can spawn thread easily.
    in the dlg class, i have the thread create and start there. I cant seem to figure a way to have the worker thread access data (dlg value stuff or variable i create in the dlg class)

    is it possible to pass a pointer to the worker thread and cast it to become a pointer for the dlg class?

    sample please

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Hannover, Germany
    Yes, that's possible. But it's a syncronisation nightmare. If you want to pass read only variables, use a struct and pass it as your parameter of the thread function. If you need feedback ( for example progress messages ) pass the window handle and PostMessage messages to this handle.

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    Unregistered User
    Join Date
    Sep 2005
    pass a pointer of the dlg class to the worker class via a setter or constructor. Maybe have a generic "parent window" pointer as a member of the generic thread class. There are many ways to do it. Just make sure you use critical sections when modifying and accessing the data.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  2. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 10:10 AM
  3. Could somebody please help me with this C program
    By brett73 in forum C Programming
    Replies: 6
    Last Post: 11-25-2004, 02:19 AM
  4. towers of hanoi problem
    By aik_21 in forum C Programming
    Replies: 1
    Last Post: 10-02-2004, 01:34 PM
  5. Replies: 2
    Last Post: 02-07-2002, 09:39 AM