Added an ActivityLock for locking into an activity state
This commit is contained in:
@@ -21,13 +21,6 @@ public class ContentDialogHandler(IDispatcher dispatcher) :
|
||||
{
|
||||
if (content is IPrimaryConfirmation primaryConfirmation)
|
||||
{
|
||||
List<Action> postActions = [];
|
||||
if (content is IActivityIndicator activityIndicator)
|
||||
{
|
||||
activityIndicator.Active = true;
|
||||
postActions.Add(() => activityIndicator.Active = false);
|
||||
}
|
||||
|
||||
Deferral deferral = args.GetDeferral();
|
||||
if (!await primaryConfirmation.Confirm())
|
||||
{
|
||||
@@ -36,10 +29,6 @@ public class ContentDialogHandler(IDispatcher dispatcher) :
|
||||
}
|
||||
|
||||
deferral.Complete();
|
||||
foreach (Action action in postActions)
|
||||
{
|
||||
action.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -52,13 +41,6 @@ public class ContentDialogHandler(IDispatcher dispatcher) :
|
||||
{
|
||||
if (content is ISecondaryConfirmation secondaryConfirmation)
|
||||
{
|
||||
List<Action> postActions = [];
|
||||
if (content is IActivityIndicator activityIndicator)
|
||||
{
|
||||
activityIndicator.Active = true;
|
||||
postActions.Add(() => activityIndicator.Active = false);
|
||||
}
|
||||
|
||||
Deferral deferral = args.GetDeferral();
|
||||
if (!await secondaryConfirmation.Confirm())
|
||||
{
|
||||
@@ -67,10 +49,6 @@ public class ContentDialogHandler(IDispatcher dispatcher) :
|
||||
}
|
||||
|
||||
deferral.Complete();
|
||||
foreach (Action action in postActions)
|
||||
{
|
||||
action.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,18 +2,33 @@
|
||||
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public class ActivityLock(IActivityIndicator activityIndicator) : AsyncLock
|
||||
{
|
||||
public override TaskAwaiter<AsyncLock> GetAwaiter()
|
||||
{
|
||||
activityIndicator.Active = true;
|
||||
return base.GetAwaiter();
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
activityIndicator.Active = false;
|
||||
base.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public class AsyncLock(int initial = 1,
|
||||
int maximum = 1) :
|
||||
IDisposable
|
||||
{
|
||||
private readonly SemaphoreSlim semaphore = new(initial, maximum);
|
||||
|
||||
public void Dispose()
|
||||
public virtual void Dispose()
|
||||
{
|
||||
semaphore.Release();
|
||||
}
|
||||
|
||||
public TaskAwaiter<AsyncLock> GetAwaiter() => LockAsync().GetAwaiter();
|
||||
public virtual TaskAwaiter<AsyncLock> GetAwaiter() => LockAsync().GetAwaiter();
|
||||
|
||||
private async Task<AsyncLock> LockAsync()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user