Browse Source

Core: enable switch for thread class to execute in UI thread

Herman Schoenfeld 6 years ago
parent
commit
2ffdefa3d2
1 changed files with 4 additions and 1 deletions
  1. 4 1
      src/core/UThread.pas

+ 4 - 1
src/core/UThread.pas

@@ -64,6 +64,7 @@ Type
   TPCThreadClass = Class of TPCThread;
   TPCThread = Class(TThread)
   private
+    FExecuteUIThread : Boolean;
     FDebugStep: String;
     FStartTickCount : TTickCount;
   protected
@@ -81,6 +82,7 @@ Type
     constructor Create(CreateSuspended: Boolean);
     destructor Destroy; override;
     Property DebugStep : String read FDebugStep write FDebugStep;
+    property ExecuteUIThread : Boolean read FExecuteUIThread write FExecuteUIThread;
     property Terminated;
   End;
 
@@ -182,6 +184,7 @@ Var _threads : TPCThreadList<TPCThread>;
 constructor TPCThread.Create(CreateSuspended: Boolean);
 begin
   inherited Create(CreateSuspended);
+  FExecuteUIThread := false;
   {$IFDEF HIGHLOG}TLog.NewLog(ltdebug,Classname,'Created Thread '+IntToHex(PtrInt(Self),8));{$ENDIF}
 end;
 
@@ -206,7 +209,7 @@ begin
     {$IFDEF HIGHLOG}TLog.NewLog(ltdebug,Classname,'Starting Thread '+IntToHex(PtrInt(Self),8)+' in pos '+inttostr(i+1));{$ENDIF}
     Try
       Try
-        BCExecute;
+        if FExecuteUIThread then Synchronize(BCExecute) else BCExecute;
         FDebugStep := 'Finalized BCExecute';
       Finally
         Terminate;