Best way for worker to gain access to variables set by GUI?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Best way for worker to gain access to variables set by GUI?

  1. #1
    Join Date
    Apr 2004
    Location
    Los Angeles
    Posts
    50

    Best way for worker to gain access to variables set by GUI?

    I am converting my project from single to multi-threaded. The single threaded version has lots and lots of variables all in the dialog's class that get set by the GUI. The new worker thread consists of several functions that must use all of these variables.

    I am in the process of creating a container class that is made up of all of these variables and then either passing a copy of it to the thread function or making it global (I'll probably end up making it global so the variables dont' have to be passed to each function - call me lazy if you will. )

    Am I going about this a good way, or is there a better (less code editing, safer, etc.) way of doing it? I'm pretty sure that I should not access the variables inside the dialog class from the worker thread - hence this effort - is that correct?

    Thanks

  2. #2
    Join Date
    Feb 2002
    Posts
    5,758

    Re: Best way for worker to gain access to variables set by GUI?

    One solution is pointer and data synchronization.

    Kuphryn

  3. #3
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: Best way for worker to gain access to variables set by GUI?

    Well....the most straight-forward solution is to make all the functions that are used by that thread part of the GUI class. Make the thread function itself a static member of the GUI class. Pass the 'this' pointer at creation time to the thread and use it inside the thread to call the necessary functions. That way, there is neither the need to pass all the variables to either the thread or its functions....
    Ciao, Andreas

    "Software is like sex, it's better when it's free." - Linus Torvalds


    Article(s): Allocators (STL) Function Objects (STL)

  4. #4
    Join Date
    Apr 2004
    Location
    Los Angeles
    Posts
    50

    Re: Best way for worker to gain access to variables set by GUI?

    Quote Originally Posted by Andreas Masur
    Well....the most straight-forward solution is to make all the functions that are used by that thread part of the GUI class. Make the thread function itself a static member of the GUI class. Pass the 'this' pointer at creation time to the thread and use it inside the thread to call the necessary functions. That way, there is neither the need to pass all the variables to either the thread or its functions....
    Just what I was looking for. Thank you, sire!

  5. #5
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: Best way for worker to gain access to variables set by GUI?

    Quote Originally Posted by ecspansion
    Just what I was looking for. Thank you, sire!
    You are welcome...
    Ciao, Andreas

    "Software is like sex, it's better when it's free." - Linus Torvalds


    Article(s): Allocators (STL) Function Objects (STL)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center