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;

Comments

  1. 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)

    ReplyDelete
  2. If 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

Post a Comment