Browse Source

update BlockChain grid to be updated and invalidated from the main thread. ui controls ARE NOT thread-safe thus should always be updated from the main (UI) thread

Dmitry Boyarintsev 6 years ago
parent
commit
3706b2d799
1 changed files with 16 additions and 3 deletions
  1. 16 3
      src/gui-classic/UGridUtils.pas

+ 16 - 3
src/gui-classic/UGridUtils.pas

@@ -210,12 +210,17 @@ Type
 
 
   TBlockChainGrid = Class;
   TBlockChainGrid = Class;
 
 
+  { TBlockChainGridUpdateThread }
+
   TBlockChainGridUpdateThread = Class(TPCThread)
   TBlockChainGridUpdateThread = Class(TPCThread)
     FBlockChainGrid : TBlockChainGrid;
     FBlockChainGrid : TBlockChainGrid;
     FBlockStart, FBlockEnd : Int64;
     FBlockStart, FBlockEnd : Int64;
     procedure DoUpdateBlockChainGrid(ANode : TNode; var AList : TList<TBlockChainData>; ABlockStart, ABlockEnd : Int64);
     procedure DoUpdateBlockChainGrid(ANode : TNode; var AList : TList<TBlockChainData>; ABlockStart, ABlockEnd : Int64);
   protected
   protected
     procedure BCExecute; override;
     procedure BCExecute; override;
+  protected
+    FGridUpdateCount: Integer;
+    procedure UpdateDrawGrid;
   public
   public
     constructor Create(ABlockChainGrid : TBlockChainGrid);
     constructor Create(ABlockChainGrid : TBlockChainGrid);
   End;
   End;
@@ -1341,9 +1346,9 @@ begin
         FBlockChainGrid.FBlockChainDataList.Add(Llist[i]);
         FBlockChainGrid.FBlockChainDataList.Add(Llist[i]);
       end;
       end;
       if Assigned(FBlockChainGrid.DrawGrid) then begin
       if Assigned(FBlockChainGrid.DrawGrid) then begin
-        if Llist.Count>0 then FBlockChainGrid.DrawGrid.RowCount := Llist.Count+1
-        else FBlockChainGrid.DrawGrid.RowCount := 2;
-        FBlockChainGrid.FDrawGrid.Invalidate;
+        if Llist.Count>0 then FGridUpdateCount := Llist.Count+1
+        else FGridUpdateCount := 2;
+        Synchronize(UpdateDrawGrid);
       end;
       end;
     end;
     end;
   finally
   finally
@@ -1351,6 +1356,14 @@ begin
   end;
   end;
 end;
 end;
 
 
+procedure TBlockChainGridUpdateThread.UpdateDrawGrid;
+begin
+  if not Assigned(FBlockChainGrid) or not Assigned(FBlockChainGrid.DrawGrid)
+    then Exit;
+  FBlockChainGrid.DrawGrid.RowCount := FGridUpdateCount;
+  FBlockChainGrid.FDrawGrid.Invalidate;
+end;
+
 constructor TBlockChainGridUpdateThread.Create(ABlockChainGrid : TBlockChainGrid);
 constructor TBlockChainGridUpdateThread.Create(ABlockChainGrid : TBlockChainGrid);
 begin
 begin
   FBlockChainGrid := ABlockChainGrid;
   FBlockChainGrid := ABlockChainGrid;