Ja So ein ähnliches System benutze ich bereits. Nur eben nicht für Messages sondern für TThreadMethods.
Delphi-Quellcode:
Procedure QueueMethod(aThreadMethod:TThreadMethod; QueueType:TQueueType=qtNone; Sender:TObject = nil );
implementation
type
TQThread = Class(TThread)
Public
ThreadMethod:TThreadMethod;
Procedure Execute;Override;
end;
Procedure QueueMethod(aThreadMethod:TThreadMethod; QueueType:TQueueType=qtNone; Sender:TObject = nil );
var aThread:TQThread;
Begin
case QueueType of
qtNone: aThreadMethod; //direkt ausführen
qtThread,qtIdle:
Begin//Vom CPU Scheduler verzögern lassen
if (MainThreadID = TThread.Current.ThreadID) then
Begin
aThread := TQThread.Create(true);
aThread.FreeOnTerminate := True;
aThread.ThreadMethod := aThreadMethod;
aThread.Resume;
end
else
Begin
{$o-}
TThread.ForceQueue(nil,aThreadMethod);
{$o+}
End;
End;
end;
End;
{ TQThread }
procedure TQThread.Execute;
begin
{$o-}
TThread.ForceQueue(nil,ThreadMethod);
{$o+}
end;