Skip to content

Commit

Permalink
Use lock when updating devices.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbound committed May 7, 2021
1 parent d2a28ce commit 6a64e2d
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions Server/Components/Devices/DevicesFrame.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace Remotely.Server.Components.Devices
[Authorize]
public partial class DevicesFrame : AuthComponentBase, IDisposable
{
private readonly object _devicesLock = new();
private readonly List<Device> _allDevices = new();
private readonly string _deviceGroupAll = Guid.NewGuid().ToString();
private readonly string _deviceGroupNone = Guid.NewGuid().ToString();
Expand Down Expand Up @@ -89,8 +90,11 @@ public void Dispose()

public void Refresh()
{
LoadDevices();
InvokeAsync(StateHasChanged);
lock (_devicesLock)
{
LoadDevices();
InvokeAsync(StateHasChanged);
}
}

protected override async Task OnInitializedAsync()
Expand All @@ -112,15 +116,21 @@ protected override async Task OnInitializedAsync()

_sortableProperties.AddRange(sortableProperties);

LoadDevices();
lock (_devicesLock)
{
LoadDevices();
}
}

protected override bool ShouldRender()
{
var shouldRender = base.ShouldRender();
if (shouldRender)
{
FilterDevices();
lock (_devicesLock)
{
FilterDevices();
}
}
return shouldRender;
}
Expand Down

0 comments on commit 6a64e2d

Please sign in to comment.