ThreadSnapshot in Thread
Posted: Thu Jan 11, 2024 1:56 pm
The problem is this. For each screenshot I create a new thread. I pass the name of the screenshot I want to receive to the stream. The thread is running and must exit. If I set the thread to complete automatically, the program closes after the first screenshot is taken. Now the code works, but the size of the memory occupied by the program is constantly growing. How to solve this problem?
Code: Select all
procedure TForm1.GetImageBS(Lac,Sid,zadanie,UserID,ZOOM:string);
Var
..
begin
var FThread : TCEFBrowserThread := TCEFBrowserThread.Create(HtmLFileName, 1024, 1024);
FThread.OnError := Thread_OnError;
FThread.OnSnapshotAvailable := Thread_OnSnapshotAvailable;
FThread.OnTerminate := ThreadTerminated;
FThread.L:=La;
FThread.s:=si;
FThread.UserID:=UID;
FThread.zadanie:=zadanie;
FThread.HTML:=HtmLFileName;
if (ZO<>'') and TrySTRTOINT(z,Temp) then FThread.z:=zo else FThread.z:='';
FThread.Start;
end;
...
procedure TForm1.Thread_OnSnapshotAvailable(Sender: TObject);
var
TempBitmap : TBitmap;
JPEG: TJPEGImage;
SendRes:boolean;
FThread : TCEFBrowserThread absolute Sender;
begin
TempBitmap := nil;
memo1.Lines.Add('Запущен поток: '+FThread.L+'_'+FThread.s+'_'+FThread.UID+'_'+FThread.zadanie);
JPEG := TJPEGImage.Create;
if (FThread <> nil) and FThread.CopySnapshot(TempBitmap) then
begin
JPEG.Assign(TempBitmap);
Image1.Picture.Assign(JPEG);
if fileexists(extractfilepath(Application.ExeName)+'\BS_image\'+FThread.L+'_'+FThread.s+FThread.z+'.jpg') then
begin
if not (FThread.UID='') then
begin
....
end;
FThread.TerminateBrowserThread;
exit;
end;
JPEG.SaveToFile(extractfilepath(Application.ExeName)+'\BS_image\'+FThread.L+'_'+FThread.s+FThread.z+'.jpg');
JPEG.Free;
if not (FThread.UserID='') then
begin
.....
end;
FThread.TerminateBrowserThread;
end;
end;