Home » Community » Newbie corner » While loop, sleep
Re: While loop, sleep [message #60271 is a reply to message #60268] |
Sun, 29 October 2023 20:22 |
|
Klugier
Messages: 1077 Registered: September 2012 Location: Poland, Kraków
|
Senior Contributor |
|
|
Hello sniffgriff ,
You can have more than one TimeCallback or you can spawn one time callback from another. For example
Spawn callbacks:
#include <CtrlLib/CtrlLib.h>
using namespace Upp;
class MyApp : public TopWindow {
MyApp() {
SetTimeCallback(1000, [=] { Action1(); }); // The first parameter is positive, time callback will be executed only once
}
void Action1() {
SetTimeCallback(2000, [=] { Action2(); }); // Execute Action2 after 2 seconds...
}
void Action2() {
SetTimeCallback(5000, [=] { Action3(); }); // Execute Action3 after 5 seconds...
}
void Action3() {
// It's over no new time callbacks will be executed
}
};
Having more than one callback time callback:
class MyApp : public TopWindow {
MyApp() {
// The third parameter of SetTimeCallback is id. If id's are different there are
// separate entities and you can schedule multiple time callbacks at once.
SetTimeCallback(1000, [=] { Action1(); }, 0); // Execute Action1() after 1s
SetTimeCallback(4000, [=] { Action2(); }, 1); // Execute Action2() after 4s
SetTimeCallback(7000, [=] { Action3(); }, 2); // Execute Action3() after 7s
}
void Action1() {}
void Action2() {}
void Action3() {}
};
I hope it will help.
Klugier
U++ - one framework to rule them all.
|
|
|
|
|
While loop, sleep
|
|
|
Re: While loop, sleep
By: koldo on Thu, 26 October 2023 09:03
|
|
|
Re: While loop, sleep
By: Oblivion on Thu, 26 October 2023 11:44
|
|
|
Re: While loop, sleep
|
|
|
Re: While loop, sleep
By: Oblivion on Thu, 26 October 2023 17:44
|
|
|
Re: While loop, sleep
|
|
|
Re: While loop, sleep
By: Oblivion on Thu, 26 October 2023 21:03
|
|
|
Re: While loop, sleep
|
|
|
Re: While loop, sleep
By: zsolt on Fri, 27 October 2023 17:43
|
|
|
Re: While loop, sleep
By: Klugier on Fri, 27 October 2023 21:50
|
|
|
Re: While loop, sleep
|
|
|
Re: While loop, sleep
By: Klugier on Sun, 29 October 2023 20:22
|
|
|
Re: While loop, sleep
|
Goto Forum:
Current Time: Thu Jun 06 08:03:48 CEST 2024
Total time taken to generate the page: 0.02095 seconds
|