Browse Source

Merge pull request #10734 from AvaloniaUI/feature/priorities-change

Make DispatcherPriority values more in line with WPF
pull/10743/head
Max Katz 3 years ago
committed by GitHub
parent
commit
74d0241e7f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 108
      src/Avalonia.Base/Threading/DispatcherPriority.cs

108
src/Avalonia.Base/Threading/DispatcherPriority.cs

@ -16,64 +16,64 @@ namespace Avalonia.Threading
{
Value = value;
}
/// <summary>
/// Minimum possible priority that's actually dispatched, default value
/// </summary>
internal static readonly DispatcherPriority MinimumActiveValue = new(0);
/// <summary>
/// A dispatcher priority for jobs that shouldn't be executed yet
/// The lowest foreground dispatcher priority
/// </summary>
public static DispatcherPriority Inactive => new(MinimumActiveValue - 1);
internal static readonly DispatcherPriority Default = new(0);
/// <summary>
/// Minimum valid priority
/// The job will be processed with the same priority as input.
/// </summary>
internal static readonly DispatcherPriority MinValue = new(Inactive);
public static readonly DispatcherPriority Input = new(Default - 1);
/// <summary>
/// Used internally in dispatcher code
/// The job will be processed after other non-idle operations have completed.
/// </summary>
public static DispatcherPriority Invalid => new(MinimumActiveValue - 2);
public static readonly DispatcherPriority Background = new(Input - 1);
/// <summary>
/// The job will be processed after background operations have completed.
/// </summary>
public static readonly DispatcherPriority ContextIdle = new(Background - 1);
/// <summary>
/// The job will be processed when the system is idle.
/// The job will be processed when the application is idle.
/// </summary>
[Obsolete("WPF compatibility")] public static readonly DispatcherPriority SystemIdle = MinimumActiveValue;
public static readonly DispatcherPriority ApplicationIdle = new (ContextIdle - 1);
/// <summary>
/// The job will be processed when the application is idle.
/// The job will be processed when the system is idle.
/// </summary>
[Obsolete("WPF compatibility")] public static readonly DispatcherPriority ApplicationIdle = new (SystemIdle + 1);
public static readonly DispatcherPriority SystemIdle = new(ApplicationIdle - 1);
/// <summary>
/// The job will be processed after background operations have completed.
/// Minimum possible priority that's actually dispatched, default value
/// </summary>
[Obsolete("WPF compatibility")] public static readonly DispatcherPriority ContextIdle = new(ApplicationIdle + 1);
internal static readonly DispatcherPriority MinimumActiveValue = new(SystemIdle);
/// <summary>
/// The job will be processed with normal priority.
/// A dispatcher priority for jobs that shouldn't be executed yet
/// </summary>
#pragma warning disable CS0618
public static readonly DispatcherPriority Normal = new(ContextIdle + 1);
#pragma warning restore CS0618
public static readonly DispatcherPriority Inactive = new(MinimumActiveValue - 1);
/// <summary>
/// The job will be processed after other non-idle operations have completed.
/// Minimum valid priority
/// </summary>
public static readonly DispatcherPriority Background = new(MinValue + 1);
internal static readonly DispatcherPriority MinValue = new(Inactive);
/// <summary>
/// The job will be processed with the same priority as input.
/// Used internally in dispatcher code
/// </summary>
public static readonly DispatcherPriority Input = new(Background + 1);
public static readonly DispatcherPriority Invalid = new(MinimumActiveValue - 2);
/// <summary>
/// The job will be processed after layout and render but before input.
/// </summary>
public static readonly DispatcherPriority Loaded = new(Input + 1);
public static readonly DispatcherPriority Loaded = new(Default + 1);
/// <summary>
/// The job will be processed with the same priority as render.
@ -98,12 +98,19 @@ namespace Avalonia.Threading
/// <summary>
/// The job will be processed with the same priority as data binding.
/// </summary>
[Obsolete("WPF compatibility")] public static readonly DispatcherPriority DataBind = MinValue;
[Obsolete("WPF compatibility")] public static readonly DispatcherPriority DataBind = new(Layout);
/// <summary>
/// The job will be processed with normal priority.
/// </summary>
#pragma warning disable CS0618
public static readonly DispatcherPriority Normal = new(DataBind + 1);
#pragma warning restore CS0618
/// <summary>
/// The job will be processed before other asynchronous operations.
/// </summary>
public static readonly DispatcherPriority Send = new(Layout + 1);
public static readonly DispatcherPriority Send = new(Normal + 1);
/// <summary>
/// Maximum possible priority
@ -151,5 +158,42 @@ namespace Avalonia.Threading
if (priority < Inactive || priority > MaxValue)
throw new ArgumentException("Invalid DispatcherPriority value", parameterName);
}
#pragma warning disable CS0618
public override string ToString()
{
if (this == Invalid)
return nameof(Invalid);
if (this == Inactive)
return nameof(Inactive);
if (this == SystemIdle)
return nameof(SystemIdle);
if (this == ContextIdle)
return nameof(ContextIdle);
if (this == ApplicationIdle)
return nameof(ApplicationIdle);
if (this == Background)
return nameof(Background);
if (this == Input)
return nameof(Input);
if (this == Default)
return nameof(Default);
if (this == Loaded)
return nameof(Loaded);
if (this == Render)
return nameof(Render);
if (this == Composition)
return nameof(Composition);
if (this == PreComposition)
return nameof(PreComposition);
if (this == DataBind)
return nameof(DataBind);
if (this == Normal)
return nameof(Normal);
if (this == Send)
return nameof(Send);
return Value.ToString();
}
#pragma warning restore CS0618
}
}

Loading…
Cancel
Save