39 lines
995 B
C#
39 lines
995 B
C#
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
using WPFluent.Extensions;
|
|||
|
|
|
|||
|
|
namespace WPFluent.Controls;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Class used to create identifiers of threads or tasks that can be performed multiple times within one instance. <see
|
|||
|
|
/// cref="Current"/> represents roughly the time in microseconds at which it was taken.
|
|||
|
|
/// </summary>
|
|||
|
|
internal class EventIdentifier
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// Creates and assigns a random value with an extra time code if possible.
|
|||
|
|
/// </summary>
|
|||
|
|
private void UpdateIdentifier() => Current = DateTime.Now.GetMicroTimestamp();
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Creates and gets the next identifier.
|
|||
|
|
/// </summary>
|
|||
|
|
public long GetNext()
|
|||
|
|
{
|
|||
|
|
UpdateIdentifier();
|
|||
|
|
|
|||
|
|
return Current;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Checks if the identifiers are the same.
|
|||
|
|
/// </summary>
|
|||
|
|
public bool IsEqual(long storedId) => Current == storedId;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Gets or sets the current identifier.
|
|||
|
|
/// </summary>
|
|||
|
|
public long Current { get; internal set; } = 0;
|
|||
|
|
}
|