Task Manager - Horizon-NTH/HorizonGUI GitHub Wiki
The TaskManager
class, part of the hgui
namespace, is a utility for scheduling and executing
tasks or functions after a specific time. It is commonly used in graphical applications to manage
tasks that require periodic execution, such as animation updates, frame rendering, or other recurring operations.
The class can be found in the header file TaskManager.h
.
-
std::string program(const std::chrono::milliseconds& delay, std::function<void()> function, std::string id = "")
: Schedules a task for execution after the specified delay. This function takes a delay duration and a function to be executed after the delay. It can also take an ID to be associated with this task; if no ID is passed, a custom one is created. This function also retrieves the ID of the newly created task. -
bool is_program(const std::string& id)
: Retrieve true if a program is scheduled for the given id. -
void deprogram(const std::string& id)
: Deprogram the task with the associated id. -
std::vector<std::string> get_ids()
: Returns the ids of all programmed tasks .
#include <hgui/header/TaskManager.h>
// Example Usage of TaskManager class
hgui::TaskManager::program(std::chrono::milliseconds(1000), []() {
// This function will be executed in 1000 milliseconds (1 second)
// Place your task here
});
// You can schedule multiple tasks with different delays and functions and even id
hgui::TaskManager::program(std::chrono::milliseconds(500), []() {
// This function will be executed in 500 milliseconds (0.5 seconds)
// Another task
}, "Task 1");
// You can then delete the task if you want to
hgui::TaskManager::deprogram("Task 1");
// Then check to see the remaining tasks:
std::vector<std::string> tasks = hgui::TaskManager::get_ids();
Note: In the "Example Usage" section, we demonstrate how to use the
TaskManager
class to schedule tasks for execution after a specific times. You can provide a delay duration and a function to be executed. This class is useful for managing time-based operations in your graphical application, such as animations and updates.