Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to previous messageGo to previous message
Klugier is currently offline  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.
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Java Script
Next Topic: How do I write string_view to Cout() without copying to a String?
Goto Forum:
  


Current Time: Thu Jun 06 08:03:48 CEST 2024

Total time taken to generate the page: 0.02095 seconds