For example from thread provided by callback from CreateTimerQueueTimer in executable or dll? It is significant to have same thread id as main thread.
procedure TMyMainClass.ExecuteMe(someparam: paramtype);
begin
{something}
end;
and
procedure TimerCallback(pvContext: pointer; fTimerOrWaitFired: boolean); stdcall;
begin
{do what ?}
end;
Final update:
All this stuff (TThread.Synchronize
, TThread.Queue
, PostThreadMessage
etc) works through messages. So be sure host application of your dll
processing messages while waiting for callback.
If you put long running work on the UI thread, you can get ANR errors. If you have multiple threads and put long running work on the non-UI threads, those non-UI threads can't inform the user of what is happening.
You can not stop the main thread while any other thread are running. (All the child threads born out of main thread.) You can use function Thread. join() to keep the main thread waiting while other thread(s) execute.
A thread can be created by implementing the Runnable interface and overriding the run() method. The Main thread in Java is the one that begins executing when the program starts.
You cannot tell the thread scheduler which order to execute threads in. If you need to ensure that a certain piece of code which is running on thread A must run before another piece of code running on thread B, you must enforce that order using locks or wait() / notify() .
To execute code in the main thread, without access to a TThread
instance, call the class methods TThread.Synchronize
or TThread.Queue
.
If you happen to be using an old Delphi compiler that does not have those methods, then SendMessage
or PostMessage
with a user defined message are the simplest solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With