File tree Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -29,7 +29,12 @@ public sealed class TestFile
2929 /// <summary>
3030 /// The image (lazy initialized value)
3131 /// </summary>
32- private Image < Rgba32 > image ;
32+ private volatile Image < Rgba32 > image ;
33+
34+ /// <summary>
35+ /// Used to ensure image loading is threadsafe.
36+ /// </summary>
37+ private readonly object syncLock = new ( ) ;
3338
3439 /// <summary>
3540 /// The image bytes
@@ -65,7 +70,21 @@ public sealed class TestFile
6570 /// <summary>
6671 /// Gets the image with lazy initialization.
6772 /// </summary>
68- private Image < Rgba32 > Image => this . image ??= ImageSharp . Image . Load < Rgba32 > ( this . Bytes ) ;
73+ private Image < Rgba32 > Image
74+ {
75+ get
76+ {
77+ if ( this . image is null )
78+ {
79+ lock ( this . syncLock )
80+ {
81+ this . image ??= ImageSharp . Image . Load < Rgba32 > ( this . Bytes ) ;
82+ }
83+ }
84+
85+ return this . image ;
86+ }
87+ }
6988
7089 /// <summary>
7190 /// Gets the input image directory.
You can’t perform that action at this time.
0 commit comments