7
7
namespace Files . App . Storage
8
8
{
9
9
/// <summary>
10
- /// Represents a synchronous/asynchronous operation on STA.
10
+ /// Represents a work scheduled to execute on a STA thread .
11
11
/// </summary>
12
12
public partial class STATask
13
13
{
14
- public static Task Run ( Action action , ILogger ? logger = null )
14
+ /// <summary>
15
+ /// Schedules the specified work to execute in a new background thread initialized with STA state.
16
+ /// </summary>
17
+ /// <param name="action">The work to execute in the STA thread.</param>
18
+ /// <param name="logger">A logger to capture any exception that occurs during execution.</param>
19
+ /// <returns>A <see cref="Task"/> that represents the work scheduled to execute in the STA thread.</returns>
20
+ public static Task Run ( Action action , ILogger ? logger )
15
21
{
16
22
var tcs = new TaskCompletionSource ( ) ;
17
23
@@ -29,7 +35,6 @@ public static Task Run(Action action, ILogger? logger = null)
29
35
{
30
36
tcs . SetResult ( ) ;
31
37
logger ? . LogWarning ( ex , "An exception was occurred during the execution within STA." ) ;
32
- tcs . SetException ( ex ) ;
33
38
}
34
39
finally
35
40
{
@@ -44,7 +49,14 @@ public static Task Run(Action action, ILogger? logger = null)
44
49
return tcs . Task ;
45
50
}
46
51
47
- public static Task < T > Run < T > ( Func < T > func , ILogger ? logger = null )
52
+ /// <summary>
53
+ /// Schedules the specified work to execute in a new background thread initialized with STA state.
54
+ /// </summary>
55
+ /// <typeparam name="T">The type of the result returned by the function.</typeparam>
56
+ /// <param name="func">The work to execute in the STA thread.</param>
57
+ /// <param name="logger">A logger to capture any exception that occurs during execution.</param>
58
+ /// <returns>A <see cref="Task"/> that represents the work scheduled to execute in the STA thread.</returns>
59
+ public static Task < T > Run < T > ( Func < T > func , ILogger ? logger )
48
60
{
49
61
var tcs = new TaskCompletionSource < T > ( ) ;
50
62
@@ -61,7 +73,6 @@ public static Task<T> Run<T>(Func<T> func, ILogger? logger = null)
61
73
{
62
74
tcs . SetResult ( default ! ) ;
63
75
logger ? . LogWarning ( ex , "An exception was occurred during the execution within STA." ) ;
64
- tcs . SetException ( ex ) ;
65
76
}
66
77
finally
67
78
{
@@ -76,7 +87,13 @@ public static Task<T> Run<T>(Func<T> func, ILogger? logger = null)
76
87
return tcs . Task ;
77
88
}
78
89
79
- public static Task Run ( Func < Task > func , ILogger ? logger = null )
90
+ /// <summary>
91
+ /// Schedules the specified work to execute in a new background thread initialized with STA state.
92
+ /// </summary>
93
+ /// <param name="func">The work to execute in the STA thread.</param>
94
+ /// <param name="logger">A logger to capture any exception that occurs during execution.</param>
95
+ /// <returns>A <see cref="Task"/> that represents the work scheduled to execute in the STA thread.</returns>
96
+ public static Task Run ( Func < Task > func , ILogger ? logger )
80
97
{
81
98
var tcs = new TaskCompletionSource ( ) ;
82
99
@@ -94,7 +111,6 @@ public static Task Run(Func<Task> func, ILogger? logger = null)
94
111
{
95
112
tcs . SetResult ( ) ;
96
113
logger ? . LogWarning ( ex , "An exception was occurred during the execution within STA." ) ;
97
- tcs . SetException ( ex ) ;
98
114
}
99
115
finally
100
116
{
@@ -109,7 +125,14 @@ public static Task Run(Func<Task> func, ILogger? logger = null)
109
125
return tcs . Task ;
110
126
}
111
127
112
- public static Task < T ? > Run < T > ( Func < Task < T > > func , ILogger ? logger = null )
128
+ /// <summary>
129
+ /// Schedules the specified work to execute in a new background thread initialized with STA state.
130
+ /// </summary>
131
+ /// <typeparam name="T">The type of the result returned by the function.</typeparam>
132
+ /// <param name="func">The work to execute in the STA thread.</param>
133
+ /// <param name="logger">A logger to capture any exception that occurs during execution.</param>
134
+ /// <returns>A <see cref="Task"/> that represents the work scheduled to execute in the STA thread.</returns>
135
+ public static Task < T ? > Run < T > ( Func < Task < T > > func , ILogger ? logger )
113
136
{
114
137
var tcs = new TaskCompletionSource < T ? > ( ) ;
115
138
@@ -126,7 +149,6 @@ public static Task Run(Func<Task> func, ILogger? logger = null)
126
149
{
127
150
tcs . SetResult ( default ) ;
128
151
logger ? . LogWarning ( ex , "An exception was occurred during the execution within STA." ) ;
129
- tcs . SetException ( ex ) ;
130
152
}
131
153
finally
132
154
{
0 commit comments