Skip to content

Commit

Permalink
Task 换成 ValueTask
Browse files Browse the repository at this point in the history
  • Loading branch information
wherewhere committed Nov 8, 2023
1 parent 45f7feb commit f463132
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions CoreAppUWP/Helpers/ThemeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ window.Content is FrameworkElement _rootElement
? rootElement.RequestedTheme
: SettingsHelper.Get<ElementTheme>(SettingsHelper.SelectedAppTheme);

public static Task<ElementTheme> GetActualThemeAsync() =>
public static ValueTask<ElementTheme> GetActualThemeAsync() =>
GetActualThemeAsync(Window.Current ?? CurrentApplicationWindow);

public static async Task<ElementTheme> GetActualThemeAsync(Window window) =>
public static async ValueTask<ElementTheme> GetActualThemeAsync(Window window) =>
window == null
? SettingsHelper.Get<ElementTheme>(SettingsHelper.SelectedAppTheme)
: window.DispatcherQueue?.HasThreadAccess == false
Expand Down Expand Up @@ -100,10 +100,10 @@ window.Content is FrameworkElement _rootElement
: ElementTheme.Default,
DispatcherQueuePriority.High).AwaitByTaskCompleteSource();

public static Task<ElementTheme> GetRootThemeAsync() =>
public static ValueTask<ElementTheme> GetRootThemeAsync() =>
GetRootThemeAsync(Window.Current ?? CurrentApplicationWindow);

public static async Task<ElementTheme> GetRootThemeAsync(Window window) =>
public static async ValueTask<ElementTheme> GetRootThemeAsync(Window window) =>
window == null
? ElementTheme.Default
: window.DispatcherQueue.HasThreadAccess
Expand Down Expand Up @@ -149,7 +149,7 @@ public static async void SetRootTheme(ElementTheme value)
UISettingChanged.Invoke(await IsDarkThemeAsync());
}

public static async Task SetRootThemeAsync(ElementTheme value)
public static async ValueTask SetRootThemeAsync(ElementTheme value)
{
await Task.WhenAll(WindowHelper.ActiveWindows.Values.Select(async window =>
{
Expand Down Expand Up @@ -230,7 +230,7 @@ public static bool IsDarkTheme()
: ActualTheme == ElementTheme.Dark;
}

public static async Task<bool> IsDarkThemeAsync()
public static async ValueTask<bool> IsDarkThemeAsync()
{
ElementTheme ActualTheme = await GetActualThemeAsync();
return Window.Current != null
Expand Down
6 changes: 3 additions & 3 deletions CoreAppUWP/Helpers/WindowHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace CoreAppUWP.Helpers
/// </summary>
public static class WindowHelper
{
public static async Task<bool> CreateWindowAsync(Action<Window> launched)
public static async ValueTask<bool> CreateWindowAsync(Action<Window> launched)
{
CoreApplicationView newView = CoreApplication.CreateNewView();
int newViewId = await newView.Dispatcher.AwaitableRunAsync(() =>
Expand All @@ -40,14 +40,14 @@ public static async Task<bool> CreateWindowAsync(Action<Window> launched)
return await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newViewId);
}

public static async Task<DesktopWindow> CreateDesktopWindowAsync(Action<DesktopWindowXamlSource> launched)
public static async ValueTask<DesktopWindow> CreateDesktopWindowAsync(Action<DesktopWindowXamlSource> launched)
{
DesktopWindow newWindow = await DesktopWindow.CreateAsync(launched).ConfigureAwait(false);
TrackWindow(newWindow);
return newWindow;
}

public static async Task<DesktopWindow> CreateDesktopWindowAsync(this DispatcherQueue dispatcherQueue, Action<DesktopWindowXamlSource> launched)
public static async ValueTask<DesktopWindow> CreateDesktopWindowAsync(this DispatcherQueue dispatcherQueue, Action<DesktopWindowXamlSource> launched)
{
DesktopWindow newWindow = await DesktopWindow.CreateAsync(dispatcherQueue, launched).ConfigureAwait(false);
TrackWindow(newWindow);
Expand Down
2 changes: 1 addition & 1 deletion CoreAppUWP/Pages/SettingsPages/SettingsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private async void HyperlinkButton_Click(object sender, RoutedEventArgs e)
}
}

public Task Refresh(bool reset = false) => Provider.Refresh(reset);
public ValueTask Refresh(bool reset = false) => Provider.Refresh(reset);

private void MarkdownText_LinkClicked(object sender, LinkClickedEventArgs e) => _ = Launcher.LaunchUriAsync(new Uri(e.Link));
}
Expand Down
4 changes: 2 additions & 2 deletions CoreAppUWP/ViewModels/SettingsPages/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public SettingsViewModel(DispatcherQueue dispatcher)
Caches[dispatcher] = this;
}

private async Task GetAboutTextBlockTextAsync(bool reset)
private async ValueTask GetAboutTextBlockTextAsync(bool reset)
{
if (reset || string.IsNullOrWhiteSpace(_aboutTextBlockText))
{
Expand All @@ -167,7 +167,7 @@ public void KeepProcess()
}
}

public async Task Refresh(bool reset)
public async ValueTask Refresh(bool reset)
{
if (reset)
{
Expand Down

0 comments on commit f463132

Please sign in to comment.