AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Threadklasse mit Event aktualisiert nicht

Ein Thema von Inspur1 · begonnen am 28. Aug 2024 · letzter Beitrag vom 29. Aug 2024
Antwort Antwort
Kas Ob.

Registriert seit: 3. Sep 2023
435 Beiträge
 
#1

AW: Threadklasse mit Event aktualisiert nicht

  Alt 29. Aug 2024, 09: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
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 04:51 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz