Einzelnen Beitrag anzeigen

Kas Ob.

Registriert seit: 3. Sep 2023
353 Beiträge
 
#19

AW: Threadklasse mit Event aktualisiert nicht

  Alt 29. Aug 2024, 10:50
@Inspur1, hi

Your posted code is wrong, it has many misconceptions, wrong ideas and usage, i am sorry can't point every one right this minute, but will point few as fast as i can as i am left with less than half hour before panned blackout:

1) The most important thing, is that never ever use CheckSynchronize, just don't, this have one place to be used and it is with non-GUI applications.
2) I think it already mentioned above, you are created a thread with CreateSuspended := False; and then after that you go with Resume, your Thread may be is already done and finished before reaching Resume.
3) By using Synchronize in Execute, you defeated the whole point of using threads in the first place as everything within Synchronize will be executed in the main thread blocking your GUI, use Synchronize only to call notifying event, and call GetHtml directly from Execute.
4) I don't understand the following and its logic:
Delphi-Quellcode:
procedure TForm1.MyTest(Sender: TObject);
begin
  // do login
  // search by title
  // get html
  // parse html
  // loop
  // --> FTest.Episodes.Add('episode0... url');
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  FTest := TSeriesThread.Create(false, MyTest);
  try
    FTest.FreeOnTerminate := false;
    FTest.Resume;
    ListBox1.Items.AddStrings(FTest.Episodes);
  finally
    FTest.Free;
  end;
end;
Notice not every event in your (GUI) forms does need Synchronize, you can use directly call notify from a thread to an event on a form, that is safe and normal, BUT your can't use any GUI element, meaning you can perform the following without Synchronize
Zitat:
// do login
// search by title
// get html
// parse html
// loop
But you can't do this without Synchronize or any other Synchronization method like PostMessage/SendMessage...
Zitat:
// --> FTest.Episodes.Add('episode0... url');
5) Your buffer of 4k is way too small.
6) Your are adding chars one by one !, this is very inefficient and slow.
7) i suggest to change that download function to grab TBytes, and overload it with one that convert the TBytes into string.
...

Hope that helps.
Kas
  Mit Zitat antworten Zitat