-
-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
99 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/Snap.Hutao/Snap.Hutao/Core/Threading/TaskContextWrapperForDispatcherQueue.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright (c) DGP Studio. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
using Microsoft.UI.Dispatching; | ||
|
||
namespace Snap.Hutao.Core.Threading; | ||
|
||
internal sealed class TaskContextWrapperForDispatcherQueue : ITaskContext | ||
{ | ||
private readonly DispatcherQueue dispatcherQueue; | ||
|
||
public TaskContextWrapperForDispatcherQueue(DispatcherQueue dispatcherQueue) | ||
{ | ||
this.dispatcherQueue = dispatcherQueue; | ||
} | ||
|
||
public void BeginInvokeOnMainThread(Action action) | ||
{ | ||
dispatcherQueue.TryEnqueue(() => action()); | ||
} | ||
|
||
public void InvokeOnMainThread(Action action) | ||
{ | ||
dispatcherQueue.Invoke(action); | ||
} | ||
|
||
public T InvokeOnMainThread<T>(Func<T> action) | ||
{ | ||
return dispatcherQueue.Invoke(action); | ||
} | ||
|
||
public ThreadPoolSwitchOperation SwitchToBackgroundAsync() | ||
{ | ||
return new(dispatcherQueue); | ||
} | ||
|
||
public DispatcherQueueSwitchOperation SwitchToMainThreadAsync() | ||
{ | ||
return new(dispatcherQueue); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters