unit System.Messaging.Extended;
interface
uses
System.SysUtils,
System.Classes,
System.Messaging,
System.Threading;
type
TMessageManagerHelper =
class helper
for TMessageManager
procedure SendMessageToQueue(
const Sender: TObject; AMessage: TMessage; ADispose: Boolean = True);
procedure SendMessageAsync(
const Sender: TObject; AMessage: TMessage; ADelayMS: Cardinal = 0; ADispose: Boolean = True);
overload;
procedure SendMessageAsync(
const Sender: TObject; AMessage: TMessage; ADispose: Boolean = True);
overload;
end;
implementation
{ TMessageManagerHelper }
procedure TMessageManagerHelper.SendMessageAsync(
const Sender: TObject; AMessage: TMessage; ADelayMS: Cardinal; ADispose: Boolean);
begin
TTask.Run(
procedure
begin
if ADelayMS > 0
then
begin
Sleep(ADelayMS);
end;
TThread.Queue(
nil,
procedure
begin
Self.SendMessage(Sender, AMessage, ADispose)
end)
end);
end;
procedure TMessageManagerHelper.SendMessageAsync(
const Sender: TObject; AMessage: TMessage; ADispose: Boolean);
begin
SendMessageAsync(Sender, AMessage, 0, ADispose);
end;
procedure TMessageManagerHelper.SendMessageToQueue(
const Sender: TObject; AMessage: TMessage; ADispose: Boolean = True);
begin
TThread.Queue(
nil,
procedure
begin
Self.SendMessage(Sender, AMessage, ADispose)
end);
end;
end.