Skip to content

Commit

Permalink
Add a lock on the reload method
Browse files Browse the repository at this point in the history
  • Loading branch information
Edward Miller committed Dec 27, 2023
1 parent 90a0af0 commit 69e1d3e
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions Maui.DataGrid/DataGrid.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public partial class DataGrid
private readonly Style _defaultSortIconStyle;

private bool _isReloading;
private readonly object _reloadLock = new();
private IList<object>? _internalItems;
private DataGridColumn? _sortedColumn;

Expand Down Expand Up @@ -1034,26 +1035,29 @@ private void OnSelectionChanged(object? sender, SelectionChangedEventArgs e)

internal void Reload()
{
if (_isReloading)
lock (_reloadLock)
{
return;
}
if (_isReloading)
{
return;
}

_isReloading = true;
_isReloading = true;

try
{
InitHeaderView();
try
{
InitHeaderView();

if (_internalItems is not null)
if (_internalItems is not null)
{
InternalItems = new List<object>(_internalItems);
}
}
finally
{
InternalItems = new List<object>(_internalItems);
_isReloading = false;
}
}
finally
{
_isReloading = false;
}
}

#endregion UI Methods
Expand Down

0 comments on commit 69e1d3e

Please sign in to comment.