|
Hellix의 ThreadTimer 콤포넌트를 사용하고 있습니다..
이넘을 동적으로 할당해 사용하고 있는데요, 동적으로 할당한뒤 interval을 주고 enable을 시키면 다른 프로세서가 interval 동안 죽어버리는군요.
즉 10초 interval을 주고 동작시킨뒤, 다른 버튼을 누른다던지 하면 10초-지난시간 뒤에 (즉 최대 10초동안은 버튼이 동작을 하지 않다가) 동작을 합니다. 이벤트를 바로 받아주지 않더군요.
그래서 소스를 봤더니..
void __fastcall TTimerThread::Execute()
{
Priority = OwnerTimer->ThreadPriority;
WORD LastStart; // Time at which the last synchronisation started
WORD LastDuration = 0; // Number of milliseconds since the last execution
while (!Terminated)
{
if (LastDuration < OwnerTimer->Interval)
// The last execution took less than the timer's interval, therefore we
// wait the difference between the two of them
SleepEx(OwnerTimer->Interval - LastDuration, false);
else
// The last execution took longer than the timer's interval, so there
// is no time to waste, if enough to process some messages to allow the
// application to do a few things
Application->ProcessMessages();
if (!Terminated) // The thread was not woken
{
LastStart = GetTickCount(); // Remember the time at which the
// synchonisation started
Synchronize(OwnerTimer->Timer);
LastDuration = GetTickCount() - LastStart; // Calculate the duration
// of the synchronisation
}
}
}
이렇게 구현되어 있는데요...
아무래도 SleepEx(OwnerTimer->Interval - LastDuration, false)
이부분에서 잡아먹고 있는것 같은데..
이부분에서 thread 이벤트가 아닌, 일반 이벤트(?)를 받아들이게 할수 없을까요 ?
제가 구성한 이 부분은 다음과 같이 타이머를 false시키고 삭제시키는 동작입니다.
void __fastcall TMainForm::btnStartStop(TObject *Sender)
{
if(ThdTimer != NULL){
ThdTimer->Enabled = false;
delete ThdTimer;
ThdTimer = NULL;
}
}
이 버튼이 타이머 interval 시간이 지난뒤 OnTimer로 할당된 함수를 부를 시점이 되어야 동작이 된다는 겁니다.
이 버튼이 바로 동작이 되게 할 수는 없을까요 ?
|