how to check is an event running at different thread?

Please discuss general Delphi programming topics here.

how to check is an event running at different thread?

Postby actalk » December 18th, 2009, 11:12 pm

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
actalk
Junior Member
Junior Member
 
Posts: 29
Joined: October 5th, 2007, 3:56 pm

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

Postby Kambiz » December 19th, 2009, 10:42 am

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
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm


Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 0 guests

cron