Content


NTL
Core
CreateTask

CreateTask


Create a task. All events are called inside lock/unlock repaint and thus you cannot run any code which will provide any paints due to the lock which will prevent real painting until last unlock. But you may create tasks in your event handlers and add them to the form. After last UnlockRepaint called on the form, it also executes all tasks and delete them from list. The task are called outside repaint locks and so you can draw and update control properties and the result will be shown immediately.

For example, lets say you want to run some continuous calculations when user click on a button and you also want to update progress on a progress bar control. So in you OnClick event handler for the button you don't have to run calculations but you have to create a task for it like shown below.

AddTask(CreateTask(([myProgressBar]() {
    // do some job and call 
    myProgressBar->setProgress(value); // to reflect changes 
})));

Don't worry about task destruction. They will be destroyed automatically right after completion. Tasks are being run in the same thread the UnlockRepaint is being called. It means UnlockRepaint blocks until all tasks finish their job.

template<class Type> ITask *CreateTask(Type run);
Namespace: nitisa
Include: Nitisa/Core/Task.h