Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

how to control Thread

Posted on 2004-09-23
3
Medium Priority
?
600 Views
Last Modified: 2010-04-05
helow

so here's my programm

i have program wich reads rows from table after its read one row programm [with TThread] sends a file to specific location.

this all works just fine but how to control this TThreads how can i know when all Threads i made finished the job.

///exsample
var finished:boolean;

programm makes 25 Threads
after all Threads finished the job >>> finished:=true;
/////////////////

thx to u
0
Comment
Question by:Kristao
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 760 total points
ID: 12131454
? why not let the therad finish itself ?
-> just do not loop in the execute-method

usual u do there


  while not terminated do
  begin
    //yourStuff
  end;
end;

you can also  do it this way

  //yourStuff
  Terminate;
end;

just as suggestion

meikl ;-)
0
 
LVL 4

Expert Comment

by:Evarest
ID: 12131507
As kretzschmar suggested you might want to let the threads terminate themselves. You can then attach an OnTerminate event to each thread. This event will then be called when it's being terminated. In this OnTerminate Event you can place dec(MyCounter) which will decrease some value. If this reaches zero, the job is finished...

Hope this helps!
Evarest
0
 
LVL 1

Author Comment

by:Kristao
ID: 12131588
? why not let the therad finish itself ?

:) becouse i need to know when all threads are finished becouse some smart ass can close the programm and all thread will be terminated even when thread is in progress :)

my programm is server so when its gets connection wich ask to make the job then reciveconnection:= false and while thread are in progres reciveconnection will still be false i need to know when last last thread ends so i could put reciveconnection:=true :)

i made something like this:

i made one counter its name is ct:integer;

ct:=rowcount

while not(table.eof) do begin
sends procedure to execute
end;

procedure Tname.Execute;

begin
  Sendfile(dend procedure here);
  synchronize(StB);
end;

procedure TName.StB;
begin
  inc(ct);
  gpr_tredi.MaxValue =ct then
  begin
    reciveconnection := true;
  end
  else begin
    lb_status.Caption := 'TThread in progress';
    lb_status.Refresh;
  end;
end;

yes its works :)

i just thout there is something more interesting then my version but thanks for good ideas

0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question