unit ThreadHelper;
interface
uses
System.Classes,
System.SysUtils;
type
TThreadHelper =
class helper
for TThread
class procedure ExecLater( AProc: TProc );
overload;
class procedure ExecLater<T>( AProc: TProc<T>; AArg: T );
overload;
class procedure ExecLater<T1, T2>( AProc: TProc<T1, T2>; AArg1: T1; AArg2: T2 );
overload;
class procedure ExecLater<T1, T2, T3>( AProc: TProc<T1, T2, T3>; AArg1: T1; AArg2: T2; AArg3: T3 );
overload;
class procedure ExecLater<T1, T2, T3, T4>( AProc: TProc<T1, T2, T3, T4>; AArg1: T1; AArg2: T2; AArg3: T3; AArg4: T4 );
overload;
end;
implementation
{ TThreadHelper }
class procedure TThreadHelper.ExecLater( AProc: TProc );
begin
TThread.CreateAnonymousThread(
procedure
begin
TThread.Current.Synchronize(
procedure
begin
AProc( );
end );
end ).Start( );
end;
class procedure TThreadHelper.ExecLater<T1, T2, T3, T4>( AProc: TProc<T1, T2, T3, T4>; AArg1: T1; AArg2: T2; AArg3: T3; AArg4: T4 );
begin
TThread.CreateAnonymousThread(
procedure
begin
TThread.Current.Synchronize(
procedure
begin
AProc( AArg1, AArg2, AArg3, AArg4 );
end );
end ).Start( );
end;
class procedure TThreadHelper.ExecLater<T1, T2, T3>( AProc: TProc<T1, T2, T3>; AArg1: T1; AArg2: T2; AArg3: T3 );
begin
TThread.CreateAnonymousThread(
procedure
begin
TThread.Current.Synchronize(
procedure
begin
AProc( AArg1, AArg2, AArg3 );
end );
end ).Start( );
end;
class procedure TThreadHelper.ExecLater<T1, T2>( AProc: TProc<T1, T2>; AArg1: T1; AArg2: T2 );
begin
TThread.CreateAnonymousThread(
procedure
begin
TThread.Current.Synchronize(
procedure
begin
AProc( AArg1, AArg2 );
end );
end ).Start( );
end;
class procedure TThreadHelper.ExecLater<T>( AProc: TProc<T>; AArg: T );
begin
TThread.CreateAnonymousThread(
procedure
begin
TThread.Current.Synchronize(
procedure
begin
AProc( AArg );
end );
end ).Start( );
end;
end.