Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

 
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 06-06-2016
Ramsay Ramsay is offline
Miembro
NULL
 
Registrado: ene 2016
Posts: 104
Poder: 9
Ramsay Va por buen camino
MultiThread cada 5 Thread

Hola , estoy usando multithread para comprobar paginas en un array largo , el tema es que funciona bien y todo , pero tendria que ser cada 10 o 5 Thread porque sino me consume mucho , me refiero a que cargue 5 thread y cuando terminen continue con otros 5 , el codigo de la unit de los threads.

Código Delphi [-]
unit ThreadsTest;

interface

uses Windows, Classes, IdHTTP;

type
  TMyThread = class(TThread)
  protected
    procedure Execute; override;
  public
    Url: String;
    ReadTimeout: Integer;
    property ReturnValue;
  end;

implementation

procedure TMyThread.Execute;
var
  IdHTTP: TIdHTTP;
begin
  if Terminated then
    Exit;
  IdHTTP := TIdHTTP.Create(nil);
  try
    IdHTTP.ReadTimeout := ReadTimeout;
    IdHTTP.Get(Url);
    ReturnValue := 1;
  finally
    IdHTTP.Free;
  end;
end;

end.

Form

Código Delphi [-]
procedure TForm1.ThreadTerminado(Sender: TObject);
var
  LThread: TMyThread;
begin
  LThread := TMyThread(Sender);
  Inc(index);
  Memo1.Lines.Add(IntToStr(index) + '-' + LThread.Url + '-' +
    IntToStr(LThread.ReturnValue));
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  i: integer;
  index: integer;
const
  paginas: array [1 .. 13] of string = ('http://localhost1', 'http://localhost',
    'http://localhost', 'http://localhost', 'http://localhost',
    'http://localhost', 'http://localhost', 'http://localhost',
    'http://localhost', 'http://localhost', 'http://localhost',
    'http://localhost', 'http://localhost');
begin
  index := 0;
  for i := Low(paginas) to High(paginas) do
  begin
    LThread := TMyThread.Create(True);
    try
      LThread.Url := paginas[i];
      LThread.ReadTimeout := 1000;
      LThread.OnTerminate := ThreadTerminado;
      LThread.FreeOnTerminate := True;
    except
      LThread.Free;
      raise;
    end;
    LThread.Resume;
  end;
end;

El array real es mas largo.

¿ Como deberia hacer esto ?
Responder Con Cita
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Multithread angelp4492 Varios 5 15-05-2012 09:09:47
Duda en Sockets MultiThread JesusRamirez Internet 3 21-08-2010 06:54:13
componente MultiFileDownloader multithread para bajar http y ftp en indy 10 softx2009 Internet 3 18-01-2010 16:17:47
Thread Paulao Varios 1 09-05-2008 00:42:34
Thread bendito thread...se me pierde la ventana Seba.F1 API de Windows 5 02-02-2006 00:16:30


La franja horaria es GMT +2. Ahora son las 01:18:35.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi