mirror of
https://github.com/BeyondDimension/SteamTools.git
synced 2026-10-29 07:27:36 +08:00
DispatcherPriority
This commit is contained in:
+27
-15
@@ -121,7 +121,7 @@ namespace System.Application.UI
|
||||
string? clrVersion;
|
||||
try
|
||||
{
|
||||
clrVersion = typeof(object).Assembly.GetRequiredCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion.Split('+', StringSplitOptions.RemoveEmptyEntries).FirstOrDefault();
|
||||
clrVersion = GetAssemblyVersion(typeof(object).Assembly);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -178,24 +178,24 @@ namespace System.Application.UI
|
||||
}
|
||||
#endif
|
||||
|
||||
b.Append("[time] ");
|
||||
GetTime(b);
|
||||
static void GetTime(StringBuilder b)
|
||||
b.Append("[time.start] ");
|
||||
GetStartTime(b);
|
||||
static void GetStartTime(StringBuilder b)
|
||||
{
|
||||
string timeString;
|
||||
string startTimeStr;
|
||||
const string f = "yy-MM-dd HH:mm:ss";
|
||||
const string f2 = "HH:mm:ss";
|
||||
const string f3 = "dd HH:mm:ss";
|
||||
var time = Process.GetCurrentProcess().StartTime;
|
||||
time = time.ToLocalTime();
|
||||
var utc_time = time.ToUniversalTime();
|
||||
var starttime = Process.GetCurrentProcess().StartTime;
|
||||
starttime = starttime.ToLocalTime();
|
||||
var utc_time = starttime.ToUniversalTime();
|
||||
var local = TimeZoneInfo.Local;
|
||||
timeString = utc_time.Hour == time.Hour
|
||||
? time.ToString(time.Year >= 2100 ? DateTimeFormat.Standard : f)
|
||||
: utc_time.Day == time.Day
|
||||
? $"{utc_time.ToString(f)}({time.ToString(f2)} {local.StandardName})"
|
||||
: $"{utc_time.ToString(f)}({time.ToString(f3)} {local.StandardName})";
|
||||
b.Append(timeString);
|
||||
startTimeStr = utc_time.Hour == starttime.Hour
|
||||
? starttime.ToString(starttime.Year >= 2100 ? DateTimeFormat.Standard : f)
|
||||
: utc_time.Day == starttime.Day
|
||||
? $"{utc_time.ToString(f)}({starttime.ToString(f2)} {local.StandardName})"
|
||||
: $"{utc_time.ToString(f)}({starttime.ToString(f3)} {local.StandardName})";
|
||||
b.Append(startTimeStr);
|
||||
}
|
||||
b.AppendLine();
|
||||
|
||||
@@ -358,7 +358,13 @@ namespace System.Application.UI
|
||||
b.AppendLine();
|
||||
#endif
|
||||
|
||||
b.Append("[essentials] ");
|
||||
#if AVALONIA
|
||||
b.Append("[avalonia.ver] ");
|
||||
b.Append(GetAssemblyVersion(typeof(global::Avalonia.Application).Assembly));
|
||||
b.AppendLine();
|
||||
#endif
|
||||
|
||||
b.Append("[essentials.supported] ");
|
||||
b.Append(Essentials.IsSupported.ToLowerString());
|
||||
b.AppendLine();
|
||||
|
||||
@@ -366,5 +372,11 @@ namespace System.Application.UI
|
||||
MessageBox.Show(b_str, "");
|
||||
}
|
||||
}
|
||||
|
||||
static string? GetAssemblyVersion(Assembly assembly)
|
||||
=> assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?
|
||||
.InformationalVersion
|
||||
.Split('+', StringSplitOptions.RemoveEmptyEntries)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Threading;
|
||||
using Xamarin.Essentials;
|
||||
using System.Application.Services;
|
||||
|
||||
@@ -27,7 +26,7 @@ namespace System.Application
|
||||
}
|
||||
}
|
||||
|
||||
public static void BeginInvokeOnMainThread(Action action, DispatcherPriorityCompat priority = DispatcherPriorityCompat.Normal)
|
||||
public static void BeginInvokeOnMainThread(Action action, DispatcherPriority priority = DispatcherPriority.Normal)
|
||||
{
|
||||
if (Essentials.IsSupported)
|
||||
{
|
||||
@@ -46,7 +45,7 @@ namespace System.Application
|
||||
}
|
||||
}
|
||||
|
||||
public static Task InvokeOnMainThreadAsync(Action action, DispatcherPriorityCompat priority = DispatcherPriorityCompat.Normal)
|
||||
public static Task InvokeOnMainThreadAsync(Action action, DispatcherPriority priority = DispatcherPriority.Normal)
|
||||
{
|
||||
if (Essentials.IsSupported)
|
||||
{
|
||||
@@ -83,7 +82,7 @@ namespace System.Application
|
||||
}
|
||||
}
|
||||
|
||||
public static Task<T> InvokeOnMainThreadAsync<T>(Func<T> func, DispatcherPriorityCompat priority = DispatcherPriorityCompat.Normal)
|
||||
public static Task<T> InvokeOnMainThreadAsync<T>(Func<T> func, DispatcherPriority priority = DispatcherPriority.Normal)
|
||||
{
|
||||
if (Essentials.IsSupported)
|
||||
{
|
||||
@@ -115,7 +114,7 @@ namespace System.Application
|
||||
}
|
||||
}
|
||||
|
||||
public static Task InvokeOnMainThreadAsync(Func<Task> funcTask, DispatcherPriorityCompat priority = DispatcherPriorityCompat.Normal)
|
||||
public static Task InvokeOnMainThreadAsync(Func<Task> funcTask, DispatcherPriority priority = DispatcherPriority.Normal)
|
||||
{
|
||||
if (Essentials.IsSupported)
|
||||
{
|
||||
@@ -148,7 +147,7 @@ namespace System.Application
|
||||
}
|
||||
}
|
||||
|
||||
public static Task<T> InvokeOnMainThreadAsync<T>(Func<Task<T>> funcTask, DispatcherPriorityCompat priority = DispatcherPriorityCompat.Normal)
|
||||
public static Task<T> InvokeOnMainThreadAsync<T>(Func<Task<T>> funcTask, DispatcherPriority priority = DispatcherPriority.Normal)
|
||||
{
|
||||
if (Essentials.IsSupported)
|
||||
{
|
||||
@@ -180,81 +179,78 @@ namespace System.Application
|
||||
return tcs.Task;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace System.Windows.Threading
|
||||
{
|
||||
/// <summary>
|
||||
/// An enunmeration describing the priorities at which
|
||||
/// operations can be invoked via the Dispatcher.
|
||||
/// <see cref="https://github.com/dotnet/wpf/blob/master/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/DispatcherPriority.cs"/>
|
||||
/// </summary>
|
||||
///
|
||||
public enum DispatcherPriorityCompat
|
||||
{
|
||||
/// <summary>
|
||||
/// Operations at this priority are processed when the system
|
||||
/// is idle.
|
||||
/// </summary>
|
||||
SystemIdle,
|
||||
|
||||
/// <summary>
|
||||
/// Minimum possible priority
|
||||
/// An enunmeration describing the priorities at which
|
||||
/// operations can be invoked via the Dispatcher.
|
||||
/// <see cref="https://github.com/dotnet/wpf/blob/master/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/DispatcherPriority.cs"/>
|
||||
/// </summary>
|
||||
MinValue = SystemIdle,
|
||||
///
|
||||
public enum DispatcherPriority
|
||||
{
|
||||
/// <summary>
|
||||
/// Operations at this priority are processed when the system
|
||||
/// is idle.
|
||||
/// </summary>
|
||||
SystemIdle,
|
||||
|
||||
/// <summary>
|
||||
/// Operations at this priority are processed when the application
|
||||
/// is idle.
|
||||
/// </summary>
|
||||
ApplicationIdle,
|
||||
/// <summary>
|
||||
/// Minimum possible priority
|
||||
/// </summary>
|
||||
MinValue = SystemIdle,
|
||||
|
||||
/// <summary>
|
||||
/// Operations at this priority are processed when the context
|
||||
/// is idle.
|
||||
/// </summary>
|
||||
ContextIdle,
|
||||
/// <summary>
|
||||
/// Operations at this priority are processed when the application
|
||||
/// is idle.
|
||||
/// </summary>
|
||||
ApplicationIdle,
|
||||
|
||||
/// <summary>
|
||||
/// Operations at this priority are processed after all other
|
||||
/// non-idle operations are done.
|
||||
/// </summary>
|
||||
Background,
|
||||
/// <summary>
|
||||
/// Operations at this priority are processed when the context
|
||||
/// is idle.
|
||||
/// </summary>
|
||||
ContextIdle,
|
||||
|
||||
/// <summary>
|
||||
/// Operations at this priority are processed at the same
|
||||
/// priority as input.
|
||||
/// </summary>
|
||||
Input,
|
||||
/// <summary>
|
||||
/// Operations at this priority are processed after all other
|
||||
/// non-idle operations are done.
|
||||
/// </summary>
|
||||
Background,
|
||||
|
||||
/// <summary>
|
||||
/// Operations at this priority are processed when layout and render is
|
||||
/// done but just before items at input priority are serviced. Specifically
|
||||
/// this is used while firing the Loaded event
|
||||
/// </summary>
|
||||
Loaded,
|
||||
/// <summary>
|
||||
/// Operations at this priority are processed at the same
|
||||
/// priority as input.
|
||||
/// </summary>
|
||||
Input,
|
||||
|
||||
/// <summary>
|
||||
/// Operations at this priority are processed at the same
|
||||
/// priority as rendering.
|
||||
/// </summary>
|
||||
Render,
|
||||
/// <summary>
|
||||
/// Operations at this priority are processed when layout and render is
|
||||
/// done but just before items at input priority are serviced. Specifically
|
||||
/// this is used while firing the Loaded event
|
||||
/// </summary>
|
||||
Loaded,
|
||||
|
||||
/// <summary>
|
||||
/// Operations at this priority are processed at normal priority.
|
||||
/// </summary>
|
||||
Normal,
|
||||
/// <summary>
|
||||
/// Operations at this priority are processed at the same
|
||||
/// priority as rendering.
|
||||
/// </summary>
|
||||
Render,
|
||||
|
||||
/// <summary>
|
||||
/// Operations at this priority are processed before other
|
||||
/// asynchronous operations.
|
||||
/// </summary>
|
||||
Send,
|
||||
/// <summary>
|
||||
/// Operations at this priority are processed at normal priority.
|
||||
/// </summary>
|
||||
Normal,
|
||||
|
||||
/// <summary>
|
||||
/// Maximum possible priority
|
||||
/// </summary>
|
||||
MaxValue = Send,
|
||||
/// <summary>
|
||||
/// Operations at this priority are processed before other
|
||||
/// asynchronous operations.
|
||||
/// </summary>
|
||||
Send,
|
||||
|
||||
/// <summary>
|
||||
/// Maximum possible priority
|
||||
/// </summary>
|
||||
MaxValue = Send,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Windows.Threading;
|
||||
using static System.Application.MainThread2;
|
||||
|
||||
namespace System.Application.Services
|
||||
{
|
||||
@@ -9,6 +9,6 @@ namespace System.Application.Services
|
||||
{
|
||||
bool PlatformIsMainThread { get; }
|
||||
|
||||
void PlatformBeginInvokeOnMainThread(Action action, DispatcherPriorityCompat priority = DispatcherPriorityCompat.Normal);
|
||||
void PlatformBeginInvokeOnMainThread(Action action, DispatcherPriority priority = DispatcherPriority.Normal);
|
||||
}
|
||||
}
|
||||
+11
-12
@@ -1,5 +1,4 @@
|
||||
using Avalonia.Threading;
|
||||
using System.Windows.Threading;
|
||||
|
||||
namespace System.Application.Services.Implementation
|
||||
{
|
||||
@@ -8,23 +7,23 @@ namespace System.Application.Services.Implementation
|
||||
public bool PlatformIsMainThread => Dispatcher.UIThread.CheckAccess();
|
||||
|
||||
public void PlatformBeginInvokeOnMainThread(Action action,
|
||||
DispatcherPriorityCompat priority = DispatcherPriorityCompat.Normal)
|
||||
MainThread2.DispatcherPriority priority = MainThread2.DispatcherPriority.Normal)
|
||||
{
|
||||
var priority_ = GetPriority(priority);
|
||||
Dispatcher.UIThread.Post(action, priority_);
|
||||
}
|
||||
|
||||
static DispatcherPriority GetPriority(DispatcherPriorityCompat priority) => priority switch
|
||||
static DispatcherPriority GetPriority(MainThread2.DispatcherPriority priority) => priority switch
|
||||
{
|
||||
DispatcherPriorityCompat.SystemIdle => DispatcherPriority.SystemIdle,
|
||||
DispatcherPriorityCompat.ApplicationIdle => DispatcherPriority.ApplicationIdle,
|
||||
DispatcherPriorityCompat.ContextIdle => DispatcherPriority.ContextIdle,
|
||||
DispatcherPriorityCompat.Background => DispatcherPriority.Background,
|
||||
DispatcherPriorityCompat.Input => DispatcherPriority.Input,
|
||||
DispatcherPriorityCompat.Loaded => DispatcherPriority.Loaded,
|
||||
DispatcherPriorityCompat.Render => DispatcherPriority.Render,
|
||||
DispatcherPriorityCompat.Normal => DispatcherPriority.Normal,
|
||||
DispatcherPriorityCompat.Send => DispatcherPriority.Send,
|
||||
MainThread2.DispatcherPriority.SystemIdle => DispatcherPriority.SystemIdle,
|
||||
MainThread2.DispatcherPriority.ApplicationIdle => DispatcherPriority.ApplicationIdle,
|
||||
MainThread2.DispatcherPriority.ContextIdle => DispatcherPriority.ContextIdle,
|
||||
MainThread2.DispatcherPriority.Background => DispatcherPriority.Background,
|
||||
MainThread2.DispatcherPriority.Input => DispatcherPriority.Input,
|
||||
MainThread2.DispatcherPriority.Loaded => DispatcherPriority.Loaded,
|
||||
MainThread2.DispatcherPriority.Render => DispatcherPriority.Render,
|
||||
MainThread2.DispatcherPriority.Normal => DispatcherPriority.Normal,
|
||||
MainThread2.DispatcherPriority.Send => DispatcherPriority.Send,
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(priority), priority, null),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
<!--(SignAssembly)对此程序集进行签名会导致编译失败(CompileAvaloniaXamlTask)-->
|
||||
<AssemblyName>System.Application.SteamTools.Client.Desktop.Avalonia</AssemblyName>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<DefineConstants>AVALONIA;$(DefineConstants)</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Properties;
|
||||
using System.Reactive;
|
||||
using System.Windows.Threading;
|
||||
using static System.Application.MainThread2;
|
||||
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace System.Application.UI.ViewModels
|
||||
@@ -75,7 +75,7 @@ namespace System.Application.UI.ViewModels
|
||||
IApplication.Instance.Shutdown();
|
||||
return true;
|
||||
default:
|
||||
MainThread2.BeginInvokeOnMainThread(() =>
|
||||
BeginInvokeOnMainThread(() =>
|
||||
{
|
||||
if (tabItemId != default)
|
||||
OnMenuClick(s =>
|
||||
@@ -83,7 +83,7 @@ namespace System.Application.UI.ViewModels
|
||||
item.Id == tabItemId, hideTaskBarWindow);
|
||||
else
|
||||
OnMenuClick(s => s.Name == tag, hideTaskBarWindow);
|
||||
}, DispatcherPriorityCompat.MaxValue);
|
||||
}, DispatcherPriority.MaxValue);
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user