79740255

Date: 2025-08-19 18:02:40
Score: 0.5
Natty:
Report link

System.Drawing.Bitmap is exceedingly not threadsafe. Even something simple like reading the "Width" property of a Bitmap will make API calls into GDI plus, and can cause GDI plus internal errors. If you need to use Bitmap in a multithreaded way, you need to wrap literally everything behind a global lock. Any method call (including static methods) or property access will require a lock, otherwise you could randomly encounter a GDI plus internal error or access violation.

Meanwhile, access to the properties of a BitmapData object (created by using LockBits) is threadsafe. If you read the properties Width, Height, Scan0, Stride, or PixelFormat, it does not make any function calls into GDI plus, instead it just reads a private field, so the properties are threadsafe. But using BitmapData still relies on the use of pointers, requiring unsafe code.

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (0.5):
Posted by: Dwedit