Platform: Delphi with VirtualTreeView SVN 5.1.0 & OmniThreadLibrary 3 SVN & Delphi XE2
Originally I thought that the problem was VirtualTreeView. I need to add node to VST every 1s or less.But It seems soon or later the CPU rate will hit 50% or more ultil the whole application becomes completely non-responsive.
var FAbort:Boolean;
.....
procedure TrmMain.btnAddNodeClick(Sender: TObject);
begin
while not FAbort do
begin
VstMain.RootNodeCount:= VstMain.RootNodeCount + 1;
Sleep(10);
Application.ProcessMessages;
end;
end;
Anyone can help? TIA!
EDIT: It seems the problem comes from the OTL. When use the code above, minimize the application the CPU alway less than 1%, even change 10ms sleep to 1ms.
But, the code below will reproduces the problem which trouble me.
procedure TForm1.btn5Click(Sender: TObject);
var
I: Integer;
begin
for I := 0 to 1 do
CreateTask(
procedure(const Task: IOmniTask)
begin
while not FAbort do
begin
Task.Comm.Send(1, 0);
Sleep(10);
end;
end).OnMessage(
procedure(const Task: IOmniTaskControl; const Msg: TOmniMessage)
begin
vst1.AddChild(nil);
end).Run;
end;
PS: For avoid the flood to the OTL default 1000 queue size, I DO have a lock in each thread that wait for the add node completed before next Task.Comm.Send operation.
PPS: The 10ms here is just for quick reproduce the problem, not in real situation. So don't bother ask why?
OK,the conclusion is: simply not add too much nodes at single node if you need to update this node periodically, the more node the more cpu time to update them.