-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Code Quality: Replaced the StartSTA helpers with STATask.Run #17405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,11 +7,17 @@ | |
namespace Files.App.Storage | ||
{ | ||
/// <summary> | ||
/// Represents a synchronous/asynchronous operation on STA. | ||
/// Represents a work scheduled to execute on a STA thread. | ||
yaira2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// </summary> | ||
public partial class STATask | ||
{ | ||
public static Task Run(Action action, ILogger? logger = null) | ||
/// <summary> | ||
/// Schedules the specified work to execute in a new background thread initialized with STA state. | ||
/// </summary> | ||
/// <param name="action">The work to execute in the STA thread.</param> | ||
/// <param name="logger">A logger to capture any exception that occurs during execution.</param> | ||
/// <returns>A <see cref="Task"/> that represents the work scheduled to execute in the STA thread.</returns> | ||
public static Task Run(Action action, ILogger? logger) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logger parameter is marked as nullable ( Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
{ | ||
var tcs = new TaskCompletionSource(); | ||
|
||
|
@@ -29,7 +35,6 @@ public static Task Run(Action action, ILogger? logger = null) | |
{ | ||
tcs.SetResult(); | ||
logger?.LogWarning(ex, "An exception was occurred during the execution within STA."); | ||
tcs.SetException(ex); | ||
} | ||
finally | ||
{ | ||
|
@@ -44,7 +49,14 @@ public static Task Run(Action action, ILogger? logger = null) | |
return tcs.Task; | ||
} | ||
|
||
public static Task<T> Run<T>(Func<T> func, ILogger? logger = null) | ||
/// <summary> | ||
/// Schedules the specified work to execute in a new background thread initialized with STA state. | ||
/// </summary> | ||
/// <typeparam name="T">The type of the result returned by the function.</typeparam> | ||
/// <param name="func">The work to execute in the STA thread.</param> | ||
/// <param name="logger">A logger to capture any exception that occurs during execution.</param> | ||
/// <returns>A <see cref="Task"/> that represents the work scheduled to execute in the STA thread.</returns> | ||
public static Task<T> Run<T>(Func<T> func, ILogger? logger) | ||
{ | ||
var tcs = new TaskCompletionSource<T>(); | ||
|
||
|
@@ -61,7 +73,6 @@ public static Task<T> Run<T>(Func<T> func, ILogger? logger = null) | |
{ | ||
tcs.SetResult(default!); | ||
logger?.LogWarning(ex, "An exception was occurred during the execution within STA."); | ||
tcs.SetException(ex); | ||
} | ||
finally | ||
{ | ||
|
@@ -76,7 +87,13 @@ public static Task<T> Run<T>(Func<T> func, ILogger? logger = null) | |
return tcs.Task; | ||
} | ||
|
||
public static Task Run(Func<Task> func, ILogger? logger = null) | ||
/// <summary> | ||
/// Schedules the specified work to execute in a new background thread initialized with STA state. | ||
/// </summary> | ||
/// <param name="func">The work to execute in the STA thread.</param> | ||
/// <param name="logger">A logger to capture any exception that occurs during execution.</param> | ||
/// <returns>A <see cref="Task"/> that represents the work scheduled to execute in the STA thread.</returns> | ||
public static Task Run(Func<Task> func, ILogger? logger) | ||
{ | ||
var tcs = new TaskCompletionSource(); | ||
|
||
|
@@ -94,7 +111,6 @@ public static Task Run(Func<Task> func, ILogger? logger = null) | |
{ | ||
tcs.SetResult(); | ||
logger?.LogWarning(ex, "An exception was occurred during the execution within STA."); | ||
tcs.SetException(ex); | ||
} | ||
finally | ||
{ | ||
|
@@ -109,7 +125,14 @@ public static Task Run(Func<Task> func, ILogger? logger = null) | |
return tcs.Task; | ||
} | ||
|
||
public static Task<T?> Run<T>(Func<Task<T>> func, ILogger? logger = null) | ||
/// <summary> | ||
/// Schedules the specified work to execute in a new background thread initialized with STA state. | ||
/// </summary> | ||
/// <typeparam name="T">The type of the result returned by the function.</typeparam> | ||
/// <param name="func">The work to execute in the STA thread.</param> | ||
/// <param name="logger">A logger to capture any exception that occurs during execution.</param> | ||
/// <returns>A <see cref="Task"/> that represents the work scheduled to execute in the STA thread.</returns> | ||
public static Task<T?> Run<T>(Func<Task<T>> func, ILogger? logger) | ||
{ | ||
var tcs = new TaskCompletionSource<T?>(); | ||
|
||
|
@@ -126,7 +149,6 @@ public static Task Run(Func<Task> func, ILogger? logger = null) | |
{ | ||
tcs.SetResult(default); | ||
logger?.LogWarning(ex, "An exception was occurred during the execution within STA."); | ||
tcs.SetException(ex); | ||
} | ||
finally | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing
null
for the logger parameter is inconsistent with other calls in this PR that useApp.Logger
. This means exceptions in thumbnail operations won't be logged, making debugging harder. Consider passing a logger instance here for consistency.Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@0x5bfa fyi