Following the thread safety guidelines from the Bitmap documentation;
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
...this should be close to the minimum locking implementation;
public static class ThreadSafe
{
private static readonly object BitmapLock = new object();
private static Bitmap _snapshot;
public static Bitmap Snapshot
{
get
{
lock (BitmapLock)
return new Bitmap(_snapshot);
}
set
{
Bitmap oldSnapshot;
Bitmap newSnapshot = new Bitmap(value, new Size(320, 240));
lock (BitmapLock)
{
oldSnapshot = _snapshot;
_snapshot = newSnapshot;
}
if (oldSnapshot != null)
oldSnapshot.Dispose();
}
}
}