Home Backgroundworking Thread Delphi 2010
Reply: 0

Backgroundworking Thread Delphi 2010

user1925
1#
user1925 Published in June 25, 2018, 3:57 am

Can someone tell me how to create a thread in Delphi 2010 which will be "standby" for data to be calculated (not to terminate after its calculation task)?

I created a program which takes data from an external source via Indy UDPServer. The IdUDPServer1UDPRead event collects data and calls different threads (depends on the type of data), but while debugging the program, I saw that the thread is being terminated after the calculation and then is being created again (the creation of the thread is taking some time). Can I create fork threads of the same thread as long as the frequency of the incoming data is greater than the CPU (or thread) can handle (a data is coming before the thread finishes the calculation).


This is the code I am trying to write:

procedure TForm1.IdUDPServer1UDPRead(AThread: TIdUDPListenerThread;
    AData: TBytes;
    ABinding:TIdSocketHandle);                                             
begin   
  form1.panel2.color:=clLime;    
  ParseDelimited(IdUDPServer1.ReceiveString,'&');    
  if (Parsedelimited=1) and (Jvthread1.Terminated=true) then
    Jvthread1.Execute(self)    
  else if (Parsedelimited=2) and (Jvthread2.Terminated=true) then
    Jvthread2.Execute(self);

  Application.ProcessMessages;
  // i know this command is not very good but by removing this line the
  //gui is responding //after 2 or 3 sec
end;

The problem is that the times it takes for the JVThread1 or JVThread2 to do the calculations is greater than the incoming data and it is my belief that this problem is caused by the time needed to create again and again the thread (maybe this is a wrong speculation). Nevertheless this is partially solved by buffering the incoming UDP Data into Indy UDPServer but when I am trying to close UDPServer nothing happens until its buffer is totally empty, which takes approximately 3-4 seconds.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.259819 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO