Click to See Complete Forum and Search --> : Using event


Johan M
May 28th, 1999, 07:13 AM
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

Franky Braem
May 28th, 1999, 07:27 AM
Isn't easier to put a pointer of CMyClass in MySecondClass? When your array changes you can call the UpdateListCtrl().