|
7 | 7 | using FineCodeCoverage.Engine; |
8 | 8 | using FineCodeCoverage.Engine.ReportGenerator; |
9 | 9 | using FineCodeCoverage.Options; |
| 10 | +using Microsoft.VisualStudio.Shell; |
10 | 11 | using Microsoft.VisualStudio.TestWindow.Extensibility; |
11 | 12 | using Microsoft.VisualStudio.Utilities; |
12 | 13 |
|
@@ -125,41 +126,43 @@ private async System.Threading.Tasks.Task TestExecutionFinishedAsync(IOperation |
125 | 126 | fccEngine.ReloadCoverage(testOperation.GetCoverageProjectsAsync); |
126 | 127 | } |
127 | 128 |
|
128 | | -#pragma warning disable VSTHRD100 // Avoid async void methods |
129 | | - private async void OperationState_StateChanged(object sender, OperationStateChangedEventArgs e) |
130 | | -#pragma warning restore VSTHRD100 // Avoid async void methods |
| 129 | + private void OperationState_StateChanged(object sender, OperationStateChangedEventArgs e) |
131 | 130 | { |
132 | | - try |
| 131 | + _ = ThreadHelper.JoinableTaskFactory.RunAsync(async () => |
133 | 132 | { |
134 | | - if(e.State == TestOperationStates.TestExecutionCanceling) |
| 133 | + try |
135 | 134 | { |
136 | | - await CombinedLogAsync("Test execution cancelling - running coverage will be cancelled."); |
137 | | - await reportGeneratorUtil.EndOfCoverageRunAsync(); // not necessarily true but get desired result |
| 135 | + if (e.State == TestOperationStates.TestExecutionCanceling) |
| 136 | + { |
| 137 | + await CombinedLogAsync("Test execution cancelling - running coverage will be cancelled."); |
| 138 | + await reportGeneratorUtil.EndOfCoverageRunAsync(); // not necessarily true but get desired result |
| 139 | + fccEngine.StopCoverage(); |
| 140 | + } |
| 141 | + |
| 142 | + |
| 143 | + if (e.State == TestOperationStates.TestExecutionStarting) |
| 144 | + { |
| 145 | + await TestExecutionStartingAsync(e.Operation); |
| 146 | + } |
| 147 | + |
| 148 | + if (e.State == TestOperationStates.TestExecutionFinished) |
| 149 | + { |
| 150 | + await TestExecutionFinishedAsync(e.Operation); |
| 151 | + } |
| 152 | + |
| 153 | + if (e.State == TestOperationStates.TestExecutionCancelAndFinished) |
| 154 | + { |
| 155 | + await CombinedLogAsync("There has been an issue running tests. See the Tests output window pane."); |
| 156 | + await reportGeneratorUtil.EndOfCoverageRunAsync(); // not necessarily true but get desired result |
138 | 157 | fccEngine.StopCoverage(); |
| 158 | + } |
139 | 159 | } |
140 | | - |
141 | | - |
142 | | - if (e.State == TestOperationStates.TestExecutionStarting) |
143 | | - { |
144 | | - await TestExecutionStartingAsync(e.Operation); |
145 | | - } |
146 | | - |
147 | | - if (e.State == TestOperationStates.TestExecutionFinished) |
| 160 | + catch (Exception exception) |
148 | 161 | { |
149 | | - await TestExecutionFinishedAsync(e.Operation); |
| 162 | + logger.Log("Error processing unit test events", exception); |
150 | 163 | } |
151 | | - |
152 | | - if (e.State == TestOperationStates.TestExecutionCancelAndFinished) |
153 | | - { |
154 | | - await CombinedLogAsync("There has been an issue running tests. See the Tests output window pane."); |
155 | | - await reportGeneratorUtil.EndOfCoverageRunAsync(); // not necessarily true but get desired result |
156 | | - fccEngine.StopCoverage(); |
157 | | - } |
158 | | - } |
159 | | - catch (Exception exception) |
160 | | - { |
161 | | - logger.Log("Error processing unit test events", exception); |
162 | | - } |
| 164 | + }); |
| 165 | + |
163 | 166 | } |
164 | 167 | } |
165 | 168 | } |
0 commit comments