6

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.

1 Answer 1

8

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.

Sign up to request clarification or add additional context in comments.

8 Comments

TThread.Synchronize requires TThread object, but callback just procedure with different thread id.
Not so. The methods I refer to are class methods and so do not need an instance.
[DCC Error] UnitMain.pas(130): E2389 Protected member 'TThread.Synchronize' is inaccessible here (Delphi XE2) on TThread.Synchronize(qt.SendEvent)
You need the two parameter version and pass nil as the first param.
It never able to execute function and never able to execute line 12181 TMonitor.Exit(ThreadLock); in System.Classes after TMonitor.Wait(SyncProcPtr.Signal, ThreadLock, INFINITE) when I trying to do that in dll.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.