Skip to content

Commit

Permalink
Lock on db context when making screenshots so fix exception related t…
Browse files Browse the repository at this point in the history
…o images loading
  • Loading branch information
Neakita committed Sep 13, 2023
1 parent f7eca0e commit 1a3cc02
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions SightKeeper.Services/Annotating/HotKeyScreenshoter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Serilog;
using SharpHook.Native;
using SightKeeper.Application.Annotating;
using SightKeeper.Data;
using SightKeeper.Domain.Model;
using SightKeeper.Domain.Services;
using SightKeeper.Services.Input;
Expand Down Expand Up @@ -49,17 +50,19 @@ public byte ScreenshotsPerSecond
}
}

public HotKeyScreenshoter(HotKeyManager hotKeyManager, DataSetScreenshoter screenshoter, ScreenshotsDataAccess librariesDataAccess)
public HotKeyScreenshoter(HotKeyManager hotKeyManager, DataSetScreenshoter screenshoter, ScreenshotsDataAccess librariesDataAccess, AppDbContext dbContext)
{
_hotKeyManager = hotKeyManager;
_screenshoter = screenshoter;
_librariesDataAccess = librariesDataAccess;
_dbContext = dbContext;
ScreenshotsPerSecond = 1;
}

private readonly HotKeyManager _hotKeyManager;
private readonly DataSetScreenshoter _screenshoter;
private readonly ScreenshotsDataAccess _librariesDataAccess;
private readonly AppDbContext _dbContext;

private IDisposable? _disposable;
private bool _isEnabled;
Expand All @@ -76,7 +79,7 @@ private void Disable()
private void OnHotKeyPressed(HotKey hotKey)
{
Guard.IsNotNull(DataSet);
lock (this)
lock (_dbContext)
{
var somethingScreenshoted = false;
while (hotKey.IsPressed)
Expand Down

0 comments on commit 1a3cc02

Please sign in to comment.