Un ejemplo bastante simple que cada 5 segundos actualiza un label con la hora, añade un botón y verás que sigue operativo mientras se va actualizando el label:
Código PHP:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <System.Threading.hpp>
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
_di_ITask tasks[1];
tasks[0] = TTask::Create([&] ()
{
Prueba();
});
tasks[0]->Start();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Prueba(void)
{
Sleep(5000);
Label1->Caption = Time();
}
//---------------------------------------------------------------------------