CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Using event

  1. #1
    Join Date
    May 1999
    Location
    L.A.
    Posts
    20

    Using event

    Hi all gurus!

    I have two classes: MyClass which contains a CListCtrl object.
    MySecondClass which contains an array MyArray.
    Depending on some events in MySecondClass, the contents of MyArray is changed.

    My problem is that MyClass contains a method which should take the values in MyArray
    and insert them into my CListCtrl object. The problem is: how can I notify this method (maybe it should
    be a thread) that MyArray has changed?

    It could be solved by using a variabel bool MyArrayChanged; and a thread like this:


    UINT MyClass::UpdateCListCtrl(LPVOID parameter) // thread which always runs
    {
    while (TRUE)
    {
    while (MySecondClass::MyArrayChanged == FALSE) // busy waiting !
    ;
    // Update CListCtrl here !
    MySecondClass::MyArrayChanged = FALSE;
    }
    return 0;
    }
    void MySecondClass::ChangeMyArray()
    {
    // change MyArray here !
    MyArrayChanged = TRUE;
    }



    But this solution requires busy waiting, the CPU runs at 100% all the time. Is it possible to
    have a more "lazy" waiting, to wake-up the thread when the array has changed?
    Or is there another way to do this CListCtrl update better (note: class MySecondClass does not inherit
    from MyClass)?

    Any suggestions?

    /Johan M


  2. #2
    Join Date
    May 1999
    Location
    Antwerp, Belgium
    Posts
    136

    Re: Using event

    Isn't easier to put a pointer of CMyClass in MySecondClass? When your array changes you can call the UpdateListCtrl().


Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured