Page 1 of 1

how to check is an event running at different thread?

PostPosted: December 18th, 2009, 11:12 pm
by actalk
Hello,

To determine is current event is runnung in main thread:

In form's constructor I set a variable
Code: Select all
testCheck := GetCurrentThreadId;


in the event :
Code: Select all
if testCheck = GetCurrentThreadId then
//running in main thread
else
//running in another thread


I wonder if this is right way?

Thanks

Re: how to check is an event running at different thread?

PostPosted: December 19th, 2009, 10:42 am
by Kambiz
It's correct.

You do not need to initialize your own testCheck variable, Delphi already declared and initiated MainThreadID variable for this purpose.

Code: Select all
if MainThreadID = GetCurrentThreadId then
  // in main thread
else
  // in child thread