Skip to content

Commit d680fa2

Browse files
authored
Fixed potential race condition (#200)
1 parent 5d8aadf commit d680fa2

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

ExtentReports/Core/MediaEntityBuilder.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class MediaEntityBuilder
88
{
99
private static readonly string Base64Encoded = "data:image/png;base64,";
1010
private static readonly MediaEntityBuilder _instance = new MediaEntityBuilder();
11-
private static ThreadLocal<Media> _media;
11+
private static ThreadLocal<Media> _media = new ThreadLocal<Media>();
1212

1313
public Media Build()
1414
{
@@ -19,10 +19,7 @@ public static MediaEntityBuilder CreateScreenCaptureFromPath(string path, string
1919
{
2020
Assert.NotEmpty(path, "ScreenCapture path must not be null or empty");
2121

22-
_media = new ThreadLocal<Media>
23-
{
24-
Value = new ScreenCapture(path, title)
25-
};
22+
_media.Value = new ScreenCapture(path, title);
2623
return _instance;
2724
}
2825

@@ -40,12 +37,9 @@ public static MediaEntityBuilder CreateScreenCaptureFromBase64String(string base
4037
base64 = Base64Encoded + base64;
4138
}
4239

43-
_media = new ThreadLocal<Media>
40+
_media.Value = new ScreenCapture(null, title)
4441
{
45-
Value = new ScreenCapture(null, title)
46-
{
47-
Base64 = base64
48-
}
42+
Base64 = base64
4943
};
5044

5145
return _instance;

0 commit comments

Comments
 (0)