pointer to main thread from worker thread?

This is a discussion on pointer to main thread from worker thread? within the C++ Programming forums, part of the General Programming Boards category; I create an MFC application in .net which create the appclass, and the dlg class i then create a generic ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    1

    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
    Location
    Hannover, Germany
    Posts
    3,139
    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.
    hth
    -nv

    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
    Location
    Antarctica
    Posts
    341
    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, 08:39 AM
  2. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 11: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, 02:34 PM
  5. Replies: 2
    Last Post: 02-07-2002, 09:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21