no if you put sleep(2000); its freeze the application, and if 10 thread are created its wait 2 second and after 10 thread created immediately no waiting, and me i want it sleep on each thread
thank you
Main Topics
Browse All TopicsHow i can do this, i want on each Thread created in wait 2 second.
my code.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
do you know your are creating threads inside the same thread type ?
what's that good for ?
use a class procedure instead
or a procedure in some other object (like a form)
and why do you type 2 exact same pieces of code except for a parameter and maybe some display procedure
btw you are using a parameter across thread boundaries
you need to synchronise the parameter access
and creating the progresbar inside the thread will certainly produce errors !
let's say you want to display the code in 2 different webbrowser windows
and you call a timing thread with Button1 and Button2
This timing thread will create a new thread every 2 secs to create a loading thread
you could use code below from a form like
type
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
WebBrowser2: TWebBrowser;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
end;
procedure TForm1.Button1Click(Sender
begin
TTimingThread.Create('http
end;
procedure TForm1.Button2Click(Sender
begin
TTimingThread.Create('http
end;
look, my code sleeps 2 seconds for each thread before getting the page.
that means that it will create all 10 threads at once, in the same second, but each thread will wait for 2 seconds before getting the webpage. so the entire operation is finished in aproximatly 2-4 seconds (maybe more, depends how long it takes to get the url).
geerts code sleeps twice as much, meaning it sleep 4 seconds for each thread: 2 seconds before it creates the thread and 2 seconds before it gets the web page.
more exactly, it will take 20 seconds to create the 10 threads and each one will wait 2 seconds before getting the webpage. the aprocimate time for the entire operation to finish is around 22-24 seconds, depending on how long it takes for the url to be downloaded.
so, I understood one thing from your post, geert probably something else. but both his and my code will wait 2 second for each thread as you asked, but you didn't mention when that waiting should happen. so geert placed it in both possible locations :) good thinking geert ;)
so, in worse case scenario, geerts code should work just fine (except if waiting 4 seconds to get a page is too much).
og, forgot to mention something about geerts code. here is a timeline:
2 seconds: thread 1 created
4 seconds: thread 1 gets the url, thread 2 created
6 seconds: thread 2 gets the url, thread 3 created
8 seconds: thread 4 gets the url, thread 4 creates
and so on.
so, as you can see, there is actually 2 seconds between each url donwload, but 4 seconds unitl the first one is done.
>> in both possible locations :) good thinking geert ;)
i assumed the idea was to load different pages so something like an animated gif would be possible
but then with webpages
little bit extravagant way to load eh ?
putting a redirect in the browser header and start it after 2 secs would be a lot easier
don't even need delphi code for that ;)
you don't need to sleep !
you need a different algorithm
1: something that starts threads to load pages and save them to file
2: and then another to load/search the files from disk
1 can work independant of 2
so no need for a sleep
the saving to file of pages can work like this:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
memUrls: TMemo;
btnStart: TButton;
edOutputDir: TEdit;
memoLog: TMemo;
procedure btnStartClick(Sender: TObject);
private
procedure TimingCallback(Msg: String; MsgInfo: Integer = 0);
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.dfm}
procedure TForm1.btnStartClick(Sende
begin
TTimingThread.Create(Timin
end;
procedure TForm1.TimingCallback(Msg:
begin
if MemoLog.Lines.Count > MaxLog then
MemoLog.Lines.Delete(0);
MemoLog.Lines.Add(Msg);
end;
end.
to search for the text in the file check this Q:
http://www.experts-exchang
I load a List of website in Memo1 and use this code to find all webpage who in the source as astrology or ASTROLOGY i use this and it very slow someone have a better idea to make it faster ?
procedure TForm1.Button7Click(Sender
var
S1: TStringList;
i: Integer;
position : Integer;
begin
S1 := TStringList.Create;
try
for i:=0 to Memo1.Lines.Count do
begin
try
S1.Clear;
label4.Caption:=(IntToStr(
memo1.lines[i] := StringReplace( memo1.lines[i],'http://','
S1.Add(IdHttp1.Get('http:/
except on e:exception do
S1.Clear;
end;
position := AnsiPos('astrology', S1.text);
if position = 0 then
else
memo2.Lines.Add(memo1.Line
label1.Caption:=(IntToStr(
position := AnsiPos('ASTROLOGY', S1.text);
if position = 0 then
else
memo2.Lines.Add(memo1.Line
label1.Caption:=(IntToStr(
end;
finally
AssignFile(myFile, 'URL.dat');
ReWrite(myFile);
WriteLn(myFile, memo2.text);
CloseFile(myFile);
end;
end;
Thank You
wow, you're using incremental indentation
what's that good for ?
please try and format the code in a delphi way
seems silly to format your code,
but i use formatting to find memory leaks
I can spot memory leaks at a glance with just formatting :)
your formatting is useless
you wanted threads
but now you're doing it in the main thread ?
Business Accounts
Answer for Membership
by: ciulyPosted on 2008-11-16 at 03:14:31ID: 22970284
you need to learn to write your code in a nice way. identation is a must. As it is, your code is unreadable. Following basic code formatiing rules ensures that everybody can read your code. When you have some time, read through the following: http://www.ciuly.com/forum /viewtopic .php?t=126
so, if all you want to do is make it wait 2 seconds before getting the webpage, simply add a sleep(2000) before getting the webpage. (I've changed your code to a more readable format plus added the sleep).
Select allOpen in new window