|
|
Home » U++ Library support » U++ Widgets - General questions or Mixed problems » howto best Ctrl Refresh handling w/ MT & very frequent refreshes
Re: howto best Ctrl Refresh handling w/ MT & very frequent refreshes [message #27036 is a reply to message #27035] |
Tue, 22 June 2010 11:45 |
|
kohait00
Messages: 939 Registered: July 2009 Location: Germany
|
Experienced Contributor |
|
|
for all those who are having app CRASHES when exiting the application, while a timer is running (triggering the refreshes on Ctrl's that dont exist anymore because of deletion). here an example solution with an Atomic variable, a bool flag and wait for an atomic state. any hints / advices / corrections welcome. so far it works for me.
sorry its just copy and paste from my application, with only some changes/deletes, but i hope the idea will be clear enough.
class ASPDevice
{
...
~ASPDevice() { DemoMode(false); } //will wait for timer to exit clean
Atomic demo; //0=disabled, 1=running demo mode, 2=a timer cb is executing
bool isdemo;
IsDemoMode() const { return isdemo; }
...
}
void ASPDevice::DemoMode(bool b)
{
bool _b = isdemo;
isdemo = b;
if(!_b && isdemo) //start only one time, maybe here is a problem still, because not atomic
{
ASSERT(AtomicInc(demo)==1);
SetTimeCallback(0, THISBACK(GenDemoData), 2);
}
else if(_b && !isdemo)
{
KillTimeCallback(2); //very important, timer might be not executin currently
AtomicDec(demo);
while(AtomicRead(demo) > 0) Sleep(1);
ASSERT(AtomicRead(demo)==0);
}
}
void ASPDevice::GenDemoData()
{
ASSERT(AtomicInc(demo)==2);
...
//do your refresh stuff here, dont forget an AtomicDec(demo) on error exits
...
int a = AtomicDec(demo);
if(a<=0) return; //if has been desabled, dont restart
ASSERT(a>=0);
ASSERT(IsDemoMode());
SetTimeCallback(200, THISBACK(GenDemoData), 2); //inkl a jitter
}
|
|
|
Goto Forum:
Current Time: Wed May 08 02:39:47 CEST 2024
Total time taken to generate the page: 0.03228 seconds
|
|
|