Using WriteableBitmapEx 1.0.8.0 from NuGet, I have some code where I'm creating a bunch of images in parrel. However, inside BitmapContext there's a static Dictionary used in the ctor - which leads to crashes when calling methods such as WriteableBitmapExtensions.Clear on different images concurrently.
Here's some code to reproduce the problem
```
Parallel.For(0, 1000, i =>
{
var bitmap = new WriteableBitmap(100, 100, 96, 96, PixelFormats.Gray16, null);
var converted = BitmapFactory.ConvertToPbgra32Format(bitmap);
converted.Clear(Colors.Aqua);
});
```
Comments: ** Comment from web user: AndreyH **
Here's some code to reproduce the problem
```
Parallel.For(0, 1000, i =>
{
var bitmap = new WriteableBitmap(100, 100, 96, 96, PixelFormats.Gray16, null);
var converted = BitmapFactory.ConvertToPbgra32Format(bitmap);
converted.Clear(Colors.Aqua);
});
```
Comments: ** Comment from web user: AndreyH **
We experienced the same issue in a multi-threading context, in a WPF application. It appears when calling
e.g. WriteableBitmap.Clear() or WriteableBitmap.DrawPolyline(int[] points, Color color)
An exception was coming from the UpdateCountByBmp-Dictionary in the 'BitmapContext.cs' (line 60).
```
private readonly static IDictionary<WriteableBitmap, int> UpdateCountByBmp = new Dictionary<WriteableBitmap, int>()
```
We changed the dictionary to a thread-safe collection and it fixed the issue for us:
```
private static readonly IDictionary<WriteableBitmap, int> UpdateCountByBmp = new System.Collections.Concurrent.ConcurrentDictionary<WriteableBitmap, int>();
```