I need some help to use a Thread...
Kellene kis segítség a Thread használatához...
http://www.lazarus.freepascal.org/index.php/topic,14291.msg75831/topicseen.html#newIf the thread is busy then the program is too busy.
Ha túlterhelt a thread akkor a program is túlterhelt.
The thread use WMI ole object and this do freeze two second, because the ole object connecting to server... Then program is too freeze on two second.
(2 connect = 4 second freeze)A programszál WMI ole objektumot használ és lefagyasztja két másodpercre, mert csatlakozik a szerverhez. Ekkor a program befagy 2 másodpercre...
(2 kapcsolódás = 4 másodperc lefagyás)The program and the thread would not run on separate?
A programnak és a threadnak nem kellene külön futniuk?
Example/Példa:
Thread working but the program can be used independently. Or no?
Thread dolgozik, de a programot attól független lehet használni. Vagy nem?
procedure TForm1.Buttom1Click(Sender: TObject);
begin
MyThread := TMyThread.Create(True);
MyThread.FreeOnTerminate := False;
MyThread.Priority := tpNormal;
MyThread.OnTerminate := @EndFunction;
MyThread.Resume;
end;
Thread unit:
unit MyThreadSource;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, MyOleWMISource;
type
TMyThread = class(TThread)
Info1 : String;
[..]
MyOleWMI : TMyOleWMI;
procedure OpenMyOleWMI;
protected
procedure Execute; override;
end;
implementation
procedure TMyThread.OpenMyOleWMI;
begin
OpenMyOleWMI := TOpenMyOleWMI.Create;
OpenMyOleWMI.SystemInfoCreate; //Class in class// = OpenMyOleWMI.System.Create;
Info1 := OpenMyOleWMI.System.InfoA;
[..]
OpenMyOleWMI.SystemInfoDestroy;
OpenMyOleWMI.Destroy;
end;
procedure TMyThread.Execute;
begin
Synchronize(@OpenMyOleWMI);
end;
end.
procedure TForm1.EndFunction(Sender: TObject);
begin
Label1.Caption := MyThread.Info1;
MyThread.Free;
end;