@@ -49,11 +49,18 @@ public async Task<AuthorizationResult> AcquireAuthorizationAsync(
49
49
{
50
50
result = await InvokeEmbeddedWebviewAsync ( authorizationUri , redirectUri , cancellationToken ) . ConfigureAwait ( false ) ;
51
51
} ) ;
52
+ #else
53
+ var sendAuthorizeRequest = new Action ( ( ) =>
54
+ {
55
+ result = InvokeEmbeddedWebview ( authorizationUri , redirectUri , cancellationToken ) ;
56
+ } ) ;
57
+ #endif
52
58
53
59
if ( Thread . CurrentThread . GetApartmentState ( ) == ApartmentState . MTA )
54
60
{
55
61
if ( _parent . SynchronizationContext != null )
56
62
{
63
+ #if WINUI3
57
64
var tcs = new TaskCompletionSource < AuthorizationResult > ( ) ;
58
65
59
66
_parent . SynchronizationContext . Post ( ( state ) =>
@@ -83,50 +90,7 @@ public async Task<AuthorizationResult> AcquireAuthorizationAsync(
83
90
} , tcs ) ;
84
91
85
92
return await tcs . Task . ConfigureAwait ( false ) ;
86
- }
87
- else
88
- {
89
- using ( var staTaskScheduler = new StaTaskScheduler ( 1 ) )
90
- {
91
- try
92
- {
93
- Task . Factory . StartNew (
94
- sendAuthorizeRequest ,
95
- cancellationToken ,
96
- TaskCreationOptions . None ,
97
- staTaskScheduler ) . Wait ( cancellationToken ) ;
98
- }
99
- catch ( AggregateException ae )
100
- {
101
- requestContext . Logger . ErrorPii ( ae . InnerException ) ;
102
- Exception innerException = ae . InnerExceptions [ 0 ] ;
103
-
104
- if ( innerException is AggregateException exception )
105
- {
106
- innerException = exception . InnerExceptions [ 0 ] ;
107
- }
108
-
109
- throw innerException ;
110
- }
111
- }
112
- }
113
- }
114
- else
115
- {
116
- await sendAuthorizeRequest ( ) . ConfigureAwait ( false ) ;
117
- }
118
-
119
- return result ;
120
93
#else
121
- var sendAuthorizeRequest = new Action ( ( ) =>
122
- {
123
- result = InvokeEmbeddedWebview ( authorizationUri , redirectUri , cancellationToken ) ;
124
- } ) ;
125
-
126
- if ( Thread . CurrentThread . GetApartmentState ( ) == ApartmentState . MTA )
127
- {
128
- if ( _parent . SynchronizationContext != null )
129
- {
130
94
var sendAuthorizeRequestWithTcs = new Action < object > ( ( tcs ) =>
131
95
{
132
96
try
@@ -147,22 +111,41 @@ public async Task<AuthorizationResult> AcquireAuthorizationAsync(
147
111
_parent . SynchronizationContext . Post (
148
112
new SendOrPostCallback ( sendAuthorizeRequestWithTcs ) , tcs2 ) ;
149
113
await tcs2 . Task . ConfigureAwait ( false ) ;
114
+ #endif
150
115
}
151
116
else
152
117
{
153
118
using ( var staTaskScheduler = new StaTaskScheduler ( 1 ) )
154
119
{
155
120
try
156
121
{
122
+ #if WINUI3
123
+ await Task . Factory . StartNew (
124
+ sendAuthorizeRequest ,
125
+ cancellationToken ,
126
+ TaskCreationOptions . None ,
127
+ staTaskScheduler ) . Unwrap ( ) . ConfigureAwait ( false ) ;
128
+ #else
157
129
Task . Factory . StartNew (
158
130
sendAuthorizeRequest ,
159
131
cancellationToken ,
160
132
TaskCreationOptions . None ,
161
133
staTaskScheduler ) . Wait ( cancellationToken ) ;
134
+ #endif
162
135
}
163
136
catch ( AggregateException ae )
164
137
{
165
138
requestContext . Logger . ErrorPii ( ae . InnerException ) ;
139
+ #if WINUI3
140
+ Exception innerException = ae . InnerExceptions [ 0 ] ;
141
+
142
+ if ( innerException is AggregateException exception )
143
+ {
144
+ innerException = exception . InnerExceptions [ 0 ] ;
145
+ }
146
+
147
+ throw innerException ;
148
+ #else
166
149
// Any exception thrown as a result of running task will cause AggregateException to be thrown with
167
150
// actual exception as inner.
168
151
Exception innerException = ae . InnerExceptions [ 0 ] ;
@@ -174,17 +157,21 @@ public async Task<AuthorizationResult> AcquireAuthorizationAsync(
174
157
}
175
158
176
159
throw innerException ;
160
+ #endif
177
161
}
178
162
}
179
163
}
180
164
}
181
165
else
182
166
{
167
+ #if WINUI3
168
+ await sendAuthorizeRequest ( ) . ConfigureAwait ( false ) ;
169
+ #else
183
170
sendAuthorizeRequest ( ) ;
171
+ #endif
184
172
}
185
173
186
174
return result ;
187
- #endif
188
175
}
189
176
190
177
public Uri UpdateRedirectUri ( Uri redirectUri )
0 commit comments