Atak_Snajpera
29th May 2012, 12:59
Worker Thread 1
EnterCriticalSection(CriticalSection1);
Server1Progress:=Received_Data; // Server1Progress is a global variable, Received_Data is declared in thread
LeaveCriticalSection(CriticalSection1);
Supervisor Thread
procedure TForm1.JvThreadSupervisorExecute(Sender: TObject; Params: Pointer);
begin
while form1.JvThreadSupervisor.Terminated=false do
begin
form1.JvThreadSupervisor.Synchronize(UpdateTotalStatusinGUI);
sleep(250);
end;
end;
procedure TForm1.UpdateTotalStatusinGUI;
begin
form1.JvListView1.Items.Item[ StrToInt(Server1AssociatedChunk)-1 ].SubItems[1] := Server1Progress;
if (Pos('encoded',Server1Progress)<>0) or (Pos('Queue',Server1Progress)<>0) then Server1Progress:='';
application.ProcessMessages;
...
And here is my question.
Do I also have to add EnterCriticalSection() and LeaveCriticalSection() in .UpdateTotalStatusinGUI ?
procedure TForm1.UpdateTotalStatusinGUI;
begin
EnterCriticalSection();
form1.JvListView1.Items.Item[ StrToInt(Server1AssociatedChunk)-1 ].SubItems[1] := Server1Progress;
if (Pos('encoded',Server1Progress)<>0) or (Pos('Queue',Server1Progress)<>0) then Server1Progress:='';
application.ProcessMessages;
LeaveCriticalSection();
...
EnterCriticalSection(CriticalSection1);
Server1Progress:=Received_Data; // Server1Progress is a global variable, Received_Data is declared in thread
LeaveCriticalSection(CriticalSection1);
Supervisor Thread
procedure TForm1.JvThreadSupervisorExecute(Sender: TObject; Params: Pointer);
begin
while form1.JvThreadSupervisor.Terminated=false do
begin
form1.JvThreadSupervisor.Synchronize(UpdateTotalStatusinGUI);
sleep(250);
end;
end;
procedure TForm1.UpdateTotalStatusinGUI;
begin
form1.JvListView1.Items.Item[ StrToInt(Server1AssociatedChunk)-1 ].SubItems[1] := Server1Progress;
if (Pos('encoded',Server1Progress)<>0) or (Pos('Queue',Server1Progress)<>0) then Server1Progress:='';
application.ProcessMessages;
...
And here is my question.
Do I also have to add EnterCriticalSection() and LeaveCriticalSection() in .UpdateTotalStatusinGUI ?
procedure TForm1.UpdateTotalStatusinGUI;
begin
EnterCriticalSection();
form1.JvListView1.Items.Item[ StrToInt(Server1AssociatedChunk)-1 ].SubItems[1] := Server1Progress;
if (Pos('encoded',Server1Progress)<>0) or (Pos('Queue',Server1Progress)<>0) then Server1Progress:='';
application.ProcessMessages;
LeaveCriticalSection();
...