Skip to content

Commit 7e0e957

Browse files
committed
Add .NET8-specific forget Task implementation
We can now rely on the built-in behavior in .NET8 to avoid throwing unobserved exceptions. We also remove the public API analyzers which aren't really adding any value, personally.
1 parent 9143d68 commit 7e0e957

File tree

7 files changed

+6
-52
lines changed

7 files changed

+6
-52
lines changed

src/Merq.Tests/Merq.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net6.0;net472</TargetFrameworks>
4+
<TargetFrameworks>net8.0;net472</TargetFrameworks>
55
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
66
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
77
<!-- Since we have our own version of the attribute in Merq.Sample -->

src/Merq/Merq.csproj

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
4+
<TargetFrameworks>netstandard2.0;net6.0;net8.0</TargetFrameworks>
55
<PackageId>Merq</PackageId>
66
<LangVersion>Latest</LangVersion>
77
<Title>
@@ -17,7 +17,6 @@
1717
<ItemGroup>
1818
<PackageReference Include="NuGetizer" />
1919
<PackageReference Include="Microsoft.CSharp" />
20-
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Pack="false" PrivateAssets="all" />
2120
<PackageReference Include="System.Threading.Tasks.Extensions" Condition="$(TargetFramework) == 'netstandard2.0'" />
2221
</ItemGroup>
2322

@@ -34,9 +33,4 @@
3433
<InternalsVisibleTo Include="Merq.Tests" />
3534
</ItemGroup>
3635

37-
<ItemGroup>
38-
<AdditionalFiles Include="PublicAPI/$(TargetFramework)/PublicAPI.Shipped.txt" Condition="Exists('PublicAPI/$(TargetFramework)/PublicAPI.Shipped.txt')" />
39-
<AdditionalFiles Include="PublicAPI/$(TargetFramework)/PublicAPI.Unshipped.txt" Condition="Exists('PublicAPI/$(TargetFramework)/PublicAPI.Unshipped.txt')" />
40-
</ItemGroup>
41-
4236
</Project>

src/Merq/PublicAPI.Shipped.txt

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/Merq/PublicAPI.Unshipped.txt

Whitespace-only changes.

src/Merq/PublicAPI/net6.0/PublicAPI.Shipped.txt

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/Merq/PublicAPI/net6.0/PublicAPI.Unshipped.txt

Whitespace-only changes.

src/Merq/TaskExtensions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ public static void Forget(this Task task)
2626
// More info about the state machine: https://blogs.msdn.microsoft.com/seteplia/2017/11/30/dissecting-the-async-methods-in-c/?WT.mc_id=DT-MVP-5003978
2727
async static Task ForgetAwaited(Task task)
2828
{
29+
#if NET8_0_OR_GREATER
30+
await task.ConfigureAwait(ConfigureAwaitOptions.SuppressThrowing);
31+
#else
2932
try
3033
{
3134
// No need to resume on the original SynchronizationContext, so use ConfigureAwait(false)
@@ -35,6 +38,7 @@ async static Task ForgetAwaited(Task task)
3538
{
3639
// Nothing to do here
3740
}
41+
#endif
3842
}
3943
}
4044
}

0 commit comments

Comments
 (0)