Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VC++ Threads update progress control / static text

Status
Not open for further replies.

LizardKingSchwing

Programmer
Oct 12, 2001
96
NL
This is probably / hopefully simple but I've a main dialog which oninit... opens a few threads whihc run in the background filling info. into list boxes , I 've added a progress control / progress text to show user what sections are being worked on ....

I've also added some member functions to the dialog which will update progress control / text however in the threads i cannot call these because they are not statics... however if I make them statice the functions give back further errors about accessing member variables in static function..

Has anyone any advice / examples on how to solve this

Cheers

LK--<
 
It's true that you can't access member vars from within a static method (how could you, the method doesn't know on which instance of the class to operate).

There are several ways you can solve this problem. For example, you can send pointers to the progressbar/labels to the threads. You can also send a pointer to your dialog class to the threads (this way the update methods CAN be non-static).

Maybe unnecessary to mention, but:
You have taken precautions while updating common stuff from multiple threads (i.e. critical sections/mutexes) ?
Greetings,
Rick
 
Thanks for the advice ...

I actually hadn't taken the precautions mentioned , but am now using a critical section lock / unlock mechanism. It works ok for a couple of threads , however I then get unhandled exceptions on the CString = operator when I try to set the Progress Text ... so i'm still looking at it and trying out some things :(

Cheers

LK--<
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top