A cross-platform UI framework for .NET
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

36 lines
812 B

using System;
using System.Threading;
namespace Avalonia.Controls
{
/// <summary>
/// Deferral class for notify that a work done in RefreshRequested event is done.
/// </summary>
public class RefreshCompletionDeferral
{
private Action _deferredAction;
private int _deferCount;
public RefreshCompletionDeferral(Action deferredAction)
{
_deferredAction = deferredAction;
}
public void Complete()
{
Interlocked.Decrement(ref _deferCount);
if (_deferCount == 0)
{
_deferredAction?.Invoke();
}
}
public RefreshCompletionDeferral Get()
{
Interlocked.Increment(ref _deferCount);
return this;
}
}
}