[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 249
  • Last Modified:

Multi Thread with idcmp.dll - Threads after some time go sleep and do not refesh Chart.

Hello,
I creating Multi Thread pinging system that drawing packet trip time. Example i created 5 thread that ping diference hosts and draw lines in charts series, but after Application minimize or after few minutes some thead don't repaint/refesh my Chart. Any solution? In threads i am newbie so please help me.

---------------------------------------------------------------
This my Thread code:
procedure TPing.Execute;
var
  Ticks: Cardinal;
  Time:  Cardinal;
  Succ:  Boolean;
  Ping:  TPingDLL;
  Index: Byte;
begin
  Ping:=TPingDLL.Create;
  Ping.SetTimeOut(StrToInt(Form1.TimeOut.Text));
 while not Terminated do
 begin
    sleep(0);
    if Form1.CheckBox1.Checked then
    Sleep(StrToInt(Form1.Edit1.Text));
    Ticks:= GetTickCount();
    Succ:=Ping.Ping(Ahost);
    Time:=GetTickCount-Ticks;
    Index:=Form1.HostList.Items.Indexof(Ahost);
    Inc(Pinger[Index].ASent);

    if Succ then
    begin
      Pinger[Form1.HostList.Items.Indexof(Ahost)].Chart.Series[0].Add(Time, '', clred);
      Inc(Pinger[Index].AReceived);
    end
   else
      begin
        Pinger[Index].Chart.Series[0].Add(0, '', clred);
        Form1.TimeOutList.Items.Insert(0, TimeToStr(now)+': '+ Ahost + TIMEOUT_MSG);
        Inc(Pinger[Index].ALoss);
      end;


    if (Time > Pinger[Index].Maximum) and Succ then
    Pinger[Index].Maximum :=Time;

    if (Time < Pinger[Index].Minimum) and Succ then
    Pinger[Index].Minimum:=Time;

    Pinger[Index].Average:=(Round(((Pinger[Index].ASent * Pinger[Index].Average)+ Time)/(Pinger[Index].ASent+1)));

    Pinger[Index].Chart.BottomAxis.Title.Caption:=SENT_PACKETS + IntToStr(Pinger[Index].ASent) +  RECEIVED_PACKETS + IntToStr(Pinger[Index].AReceived)+ LOSS_PACKETS + IntToStr(Pinger[Index].ALoss)+
    MAX_TRIP +IntToStr(Pinger[Index].Maximum)+ MIN_TRIP + IntToStr(Pinger[Index].Minimum) + AVG_TRIP + IntToStr(Pinger[Index].Average);

    if Pinger[Form1.HostList.Items.Indexof(Ahost)].ASent mod StrToInt(Form1.ASteps.Text) =0 then
    Pinger[Form1.HostList.Items.Indexof(Ahost)].Chart.Series[0].Clear;

 end;
end;

---------------------------------------------------------------
and this my structure that creats threads:
for i:=0 to Length(Pinger)-1 do
begin
      // Kuriamas Threadas
      Pinger[i].Ping:=TPing.Create(true);
      Pinger[i].Ping.AHost:=HostList.Items.Strings[i];
      Pinger[i].Ping.AName:=PINGNAME + IntToStr(i);
      Pinger[i].Ping.FreeOnTerminate:=true;
      Pinger[i].Ping.Priority:=tpTimeCritical;
      Pinger[i].Ping.Resume;
  end;
0
selas
Asked:
selas
  • 2
1 Solution
 
diniludCommented:
The Updating part of Form1 should synchronize.
0
 
selasAuthor Commented:
Can i create in a thread visual component that parent would be Tform ?
0
 
diniludCommented:
see this example


 ..\Borland\Delphi7\Demos\Threads
0
 
Computer101Commented:
Forced accept.

Computer101
EE Admin
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now