Skip to content

Commit 516b0b8

Browse files
committed
remove async - OperationState_StateChanged
1 parent 04d1890 commit 516b0b8

File tree

1 file changed

+31
-28
lines changed

1 file changed

+31
-28
lines changed

SharedProject/Impl/TestContainerDiscovery/TestContainerDiscoverer.cs

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using FineCodeCoverage.Engine;
88
using FineCodeCoverage.Engine.ReportGenerator;
99
using FineCodeCoverage.Options;
10+
using Microsoft.VisualStudio.Shell;
1011
using Microsoft.VisualStudio.TestWindow.Extensibility;
1112
using Microsoft.VisualStudio.Utilities;
1213

@@ -125,41 +126,43 @@ private async System.Threading.Tasks.Task TestExecutionFinishedAsync(IOperation
125126
fccEngine.ReloadCoverage(testOperation.GetCoverageProjectsAsync);
126127
}
127128

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)
131130
{
132-
try
131+
_ = ThreadHelper.JoinableTaskFactory.RunAsync(async () =>
133132
{
134-
if(e.State == TestOperationStates.TestExecutionCanceling)
133+
try
135134
{
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
138157
fccEngine.StopCoverage();
158+
}
139159
}
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)
148161
{
149-
await TestExecutionFinishedAsync(e.Operation);
162+
logger.Log("Error processing unit test events", exception);
150163
}
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+
163166
}
164167
}
165168
}

0 commit comments

Comments
 (0)