![]() |
AW: Multithreading GUI
Liste der Anhänge anzeigen (Anzahl: 1)
Im Anhang das komplette Projekt und hier nur das Formular. Das ist nix mit massiv paralleler Verarbeitung der Jobs, sondern ein Thread kümmert sich um die Verarbeitung der übergebenen Jobs.
Inklusive der Rückmeldung an das Formular.
Delphi-Quellcode:
unit FormMain;
interface uses ThreadedJobQueue, ProcJob, Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls; type TMainForm = class( TForm ) Button1 : TButton; CheckBox1 : TCheckBox; CheckBox2 : TCheckBox; CheckBox3 : TCheckBox; ListBox1 : TListBox; procedure Button1Click( Sender : TObject ); private FJobQueue : TThreadedJobQueue; procedure LogStr( const AStr : string ); public procedure AfterConstruction; override; procedure BeforeDestruction; override; end; var MainForm : TMainForm; implementation {$R *.dfm} procedure TMainForm.AfterConstruction; begin inherited; FJobQueue := TThreadedJobQueue.Create; end; procedure TMainForm.BeforeDestruction; begin inherited; FJobQueue.Free; end; procedure TMainForm.Button1Click( Sender : TObject ); begin if FJobQueue.IsWorking then begin LogStr( 'Nicht hektisch werden :o)' ); Exit; end; if CheckBox1.Checked then FJobQueue.AddJob( TProcJob.Construct( procedure begin LogStr( 'Start 1' ); Sleep( 1000 ); LogStr( 'Ende 1' ); end ) ); if CheckBox2.Checked then FJobQueue.AddJob( TProcJob.Construct( procedure begin LogStr( 'Start 2' ); Sleep( 1000 ); LogStr( 'Ende 2' ); end ) ); if CheckBox3.Checked then FJobQueue.AddJob( TProcJob.Construct( procedure begin LogStr( 'Start 3' ); Sleep( 1000 ); LogStr( 'Ende 3' ); end ) ); FJobQueue.ProcessJobs; end; procedure TMainForm.LogStr( const AStr : string ); begin // Diese Methode achtet von selber darauf, // dass der eigentlich Zugriff im MainThread-Context erfolgt if MainThreadID = GetCurrentThreadId then begin ListBox1.ItemIndex := ListBox1.Items.Add( AStr ); end else TThread.Queue( nil, procedure begin LogStr( AStr ); end ); end; end. |
AW: Multithreading GUI
ich versuche das mal umzusetzen und zu verstehen!
danke auf jeden Fall! |
Alle Zeitangaben in WEZ +1. Es ist jetzt 00:56 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