@@ -24,19 +24,18 @@ public class VisualUITestBase
24
24
/// </summary>
25
25
/// <param name="content">Content to set in test app.</param>
26
26
/// <returns>When UI is loaded.</returns>
27
- protected Task < bool > SetTestContentAsync ( FrameworkElement content , TaskCreationOptions ? options = null )
27
+ protected Task SetTestContentAsync ( FrameworkElement content )
28
28
{
29
- var taskCompletionSource = options . HasValue ? new TaskCompletionSource < bool > ( options . Value )
30
- : new TaskCompletionSource < bool > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
31
-
32
- App . DispatcherQueue . EnqueueAsync ( ( ) =>
29
+ return App . DispatcherQueue . EnqueueAsync ( ( ) =>
33
30
{
31
+ var taskCompletionSource = new TaskCompletionSource < bool > ( ) ;
32
+
34
33
async void Callback ( object sender , RoutedEventArgs args )
35
34
{
36
35
content . Loaded -= Callback ;
37
36
38
37
// Wait for first Render pass
39
- await CompositionTargetHelper . ExecuteAfterCompositionRenderingAsync ( ( ) => { } , TaskCreationOptions . RunContinuationsAsynchronously ) ;
38
+ await CompositionTargetHelper . ExecuteAfterCompositionRenderingAsync ( ( ) => { } ) ;
40
39
41
40
taskCompletionSource . SetResult ( true ) ;
42
41
}
@@ -53,35 +52,26 @@ async void Callback(object sender, RoutedEventArgs args)
53
52
{
54
53
taskCompletionSource . SetException ( e ) ;
55
54
}
56
- } ) ;
57
55
58
- return taskCompletionSource . Task ;
56
+ return taskCompletionSource . Task ;
57
+ } ) ;
59
58
}
60
59
61
60
[ TestCleanup ]
62
61
public async Task Cleanup ( )
63
62
{
64
63
var taskCompletionSource = new TaskCompletionSource < bool > ( ) ;
65
64
66
- // Need to await TaskCompletionSource before Task
67
- // See https://devblogs.microsoft.com/premier-developer/the-danger-of-taskcompletionsourcet-class/
68
- await taskCompletionSource . Task ;
69
-
70
65
await App . DispatcherQueue . EnqueueAsync ( ( ) =>
71
66
{
72
- void Callback ( object sender , RoutedEventArgs args )
73
- {
74
- App . ContentRoot . Unloaded -= Callback ;
75
-
76
- taskCompletionSource . SetResult ( true ) ;
77
- }
78
-
79
67
// Going to wait for our original content to unload
80
- App . ContentRoot . Unloaded += Callback ;
68
+ App . ContentRoot . Unloaded += ( _ , _ ) => taskCompletionSource . SetResult ( true ) ;
81
69
82
70
// Trigger that now
83
71
App . ContentRoot = null ;
84
72
} ) ;
73
+
74
+ await taskCompletionSource . Task ;
85
75
}
86
76
}
87
77
}
0 commit comments