Autor Beitrag
NOS1971
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 193

Windows 8.1 PRO 64 Bit
Delphi XE7 Professional
BeitragVerfasst: Fr 24.05.13 16:42 
Hallo zusammen ...
ich habe mir einen kleinen Spider geschrieben und möchte den nun multithreaded machen. hierzu habe ich mir die omnithreadlibrary installiert und mir einen AnalyseURLThread erzeugt. Dieser analysiert eine URL und gibt per PostMessage die gefundenen weiteren URL's weiter während diese dann in die Liste geadded werden noch während der Thread läuft. Das funktioniert schon super aber entweder ich beschäftige mich nun zu lange damit oder ich checks einfach nicht.

Folgendes Problem ergibt sich für mich:
ich gebe die erste URL / Domain vor und starte damit einen Thread zum analysieren ... ich kriege die Hauptschleife einfach nicht hin die mir aus der Liste die nächste URL holt und zum analysieren gibt.
Die Schleife läuft einmal durch und das wars. Zum Test added die analyse routine im moment jeweils eine url.

Hier mal der grobe Ablauf:
- initialisieren der analyse
- erste url/domain in die lsite adden
- thread starten
- while ... do schleife in der ich abfrage ob die liste abgearbeitet und keine threads mehr im threadpool laufen

Code:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
 // initialize threadings
 InitializeThreading;
 // create base url item and add it to the listview
 TempItem := lvTempSpiderResult.Items.Add;
 TempItem.Caption := cbURL.Text;
 // set end of update in listview
 lvTempSpiderResult.Items.EndUpdate;
 // set index
 CurrentIndex := 0;
 // get next item to analyse
 NextItemIndex := GetNextAnalyseItem;
 // check if the index is valid
 if (NextItemIndex < lvTempSpiderResult.Items.Count) and (NextItemIndex <> -1then
  begin
   // now start the analysis for each URL
   CreateTask(TAnalyseURLThread.Create(Handle,lvTempSpiderResult.Items[NextItemIndex].caption,NextItemIndex)).MonitorWith(OmniTED).Schedule;
   // increment index
   inc(CurrentIndex);
  end;
 while (CurrentIndex <= lvTempSpiderResult.Items.Count - 1and (GlobalOmniThreadPool.CountExecuting > 0do
  begin
   // wait for threadslot to be empty
   while GlobalOmniThreadPool.CountExecuting >= MaxThreads do
    begin
     Application.ProcessMessages;
    end;
   // check if threadslot is really empty
   if GlobalOmniThreadPool.CountExecuting < MaxThreads then
    begin
     // get next item to analyse
     NextItemIndex := GetNextAnalyseItem;
     // check if the index is valid
     if (NextItemIndex < lvTempSpiderResult.Items.Count) and (NextItemIndex <> -1then
      begin
       // now start the analysis for each URL
       CreateTask(TAnalyseURLThread.Create(Handle,lvTempSpiderResult.Items[NextItemIndex].caption,NextItemIndex)).MonitorWith(OmniTED).Schedule;
       // increment index
       inc(CurrentIndex);
      end;
    end;
  end;
 // deinitialize threadings
 DeintializeThreading;
 // resize column
 if lvTempSpiderResult.Items.Count > 0 then
  lvTempSpiderResult.AutoSizeColumns;


Ich hoffe ihr könnt mir ansatzweise helfen :-)

Grüße,
Andreas