// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.ComponentModel;
#pragma warning disable CA1001
namespace CommunityToolkit.Common.Deferred;
///
/// which can retrieve a in order to process data asynchronously before an completes and returns to the calling control.
///
public class DeferredEventArgs : EventArgs
{
///
/// Gets a new to use in cases where no wish to be provided.
///
public static new DeferredEventArgs Empty => new();
private readonly object _eventDeferralLock = new();
private EventDeferral? _eventDeferral;
///
/// Returns an which can be completed when deferred event is ready to continue.
///
/// instance.
public EventDeferral GetDeferral()
{
lock (_eventDeferralLock)
{
return _eventDeferral ??= new EventDeferral();
}
}
///
/// DO NOT USE - This is a support method used by . It is public only for
/// additional usage within extensions for the UWP based TypedEventHandler extensions.
///
/// Internal EventDeferral reference
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This is an internal only method to be used by EventHandler extension classes, public callers should call GetDeferral() instead.")]
public EventDeferral? GetCurrentDeferralAndReset()
{
lock (_eventDeferralLock)
{
EventDeferral? eventDeferral = _eventDeferral;
_eventDeferral = null;
return eventDeferral;
}
}
}