@@ -65,6 +65,11 @@ IReportGeneratorUtil reportGeneratorUtil
6565
6666 }
6767
68+ internal Action < Func < System . Threading . Tasks . Task > > RunAsync = ( taskProvider ) =>
69+ {
70+ _ = ThreadHelper . JoinableTaskFactory . RunAsync ( taskProvider ) ;
71+ } ;
72+
6873 private async System . Threading . Tasks . Task TestExecutionStartingAsync ( IOperation operation )
6974 {
7075 fccEngine . StopCoverage ( ) ;
@@ -125,15 +130,16 @@ private async System.Threading.Tasks.Task TestExecutionFinishedAsync(IOperation
125130 }
126131 fccEngine . ReloadCoverage ( testOperation . GetCoverageProjectsAsync ) ;
127132 }
128-
133+ private bool cancelling ;
129134 private void OperationState_StateChanged ( object sender , OperationStateChangedEventArgs e )
130135 {
131- _ = ThreadHelper . JoinableTaskFactory . RunAsync ( async ( ) =>
136+ RunAsync ( async ( ) =>
132137 {
133138 try
134139 {
135140 if ( e . State == TestOperationStates . TestExecutionCanceling )
136141 {
142+ cancelling = true ;
137143 await CombinedLogAsync ( "Test execution cancelling - running coverage will be cancelled." ) ;
138144 await reportGeneratorUtil . EndOfCoverageRunAsync ( ) ; // not necessarily true but get desired result
139145 fccEngine . StopCoverage ( ) ;
@@ -143,19 +149,21 @@ private void OperationState_StateChanged(object sender, OperationStateChangedEve
143149 if ( e . State == TestOperationStates . TestExecutionStarting )
144150 {
145151 await TestExecutionStartingAsync ( e . Operation ) ;
152+ cancelling = false ;
146153 }
147154
148155 if ( e . State == TestOperationStates . TestExecutionFinished )
149156 {
150157 await TestExecutionFinishedAsync ( e . Operation ) ;
151158 }
152159
153- if ( e . State == TestOperationStates . TestExecutionCancelAndFinished )
160+ if ( e . State == TestOperationStates . TestExecutionCancelAndFinished && ! cancelling )
154161 {
155162 await CombinedLogAsync ( "There has been an issue running tests. See the Tests output window pane." ) ;
156163 await reportGeneratorUtil . EndOfCoverageRunAsync ( ) ; // not necessarily true but get desired result
157- fccEngine . StopCoverage ( ) ;
164+ fccEngine . StopCoverage ( ) ;
158165 }
166+
159167 }
160168 catch ( Exception exception )
161169 {
0 commit comments