Is this code thread safe?
Is this code thread safe?
Can I access on Canvas of bitmap created on form1 but used only by my thread and not displayed / used by form1?
Eg:
TmyTh = class(TThread)
....
end;
TForm1 = class(TForm)
procedure Form create(...);
public
Bmp: TBitmap;
end;
procedure TForm1.FormCreate(...)
begin
Bmp := TBitmap.create;
....
end;
procedure TmyTh.execute;
begin
...
Form1. Bmp.Canvas.moveto(....);
Form1. Bmp.Canvas.lineto(....);
Form1. Bmp.SaveToFile(...);
end;
Can I access on Canvas of bitmap created on form1 but used only by my thread and not displayed / used by form1?
Eg:
TmyTh = class(TThread)
....
end;
TForm1 = class(TForm)
procedure Form create(...);
public
Bmp: TBitmap;
end;
procedure TForm1.FormCreate(...)
begin
Bmp := TBitmap.create;
....
end;
procedure TmyTh.execute;
begin
...
Form1. Bmp.Canvas.moveto(....);
Form1. Bmp.Canvas.lineto(....);
Form1. Bmp.SaveToFile(...);
end;
I have been using tbitmap in background threads without any issues. Sometimes lock/unlock is required, but unfortunately it currently escapes my memory what was the problem that needed it. (I'm sorry, I can't look up anything right now, my internet connection is restricted to my smartphone)
ReplyDeleteDavide Visconti please watch youtube.com - Have You Embraced Your Inner Software Plumber Yet? to see what I meant.
ReplyDeleteIf there is only one thread that draws on that bitmap, yes this is possible ! Otherwise you may need to lock/unlock any bitmap access.
ReplyDelete