SnapExit 3.0.1
This package was discontinued due to limitations in Task programming causing it to produce many memory leaks.
dotnet add package SnapExit --version 3.0.1
NuGet\Install-Package SnapExit -Version 3.0.1
<PackageReference Include="SnapExit" Version="3.0.1" />
<PackageVersion Include="SnapExit" Version="3.0.1" />
<PackageReference Include="SnapExit" />
paket add SnapExit --version 3.0.1
#r "nuget: SnapExit, 3.0.1"
#:package SnapExit@3.0.1
#addin nuget:?package=SnapExit&version=3.0.1
#tool nuget:?package=SnapExit&version=3.0.1
Snap exit 3.0.0
A nuget package that allows for exception-like behavior to validate state in any ASP.NET project, but with all the performance benefits of cancellation tokens.
Any feedback is helpful. Please leave it in the Issues section. 3.0 aims for a stable release with a few new features and a lot of bug fixes. From now on the package will be safelly maintained and updated with new features.
Performance
The package is meant to replace exceptions but still keeps the performance cost at a minimum. Still with a dept of 1 (worst case scenario). The performance is still x10 over regular exception. Most of the lost performance in this benchmarks is because of the one time cost of initialization. When u negate for that, the loss is even smaller (-200ns).
Exceptions | SnapExit | HappyPath | SnapExit HappyPath |
---|---|---|---|
11_400ns | 1300ns | 700ns | 1100ns |
When u increase the stack dept the performance of exceptions becomes worse. So with a 100 deep stack these are the benchmarking results. As you can see with a deep stack debt the performance increase can be up to x60.
Exceptions | SnapExit | HappyPath | SnapExit HappyPath |
---|---|---|---|
460μs | 5μs | 1,3μs | 1,3μs |
Usage
To throw a SnapExit it is as simple as using the static Snap class
Do not forget to await the Snap.Exit()
. if you dont the next lines might be executed
// Old way
throw new Exception(new {
// pass data to the try catch block
});
// New way
await Snap.Exit(new {
// any response data defined in the ExitManager can be passed here
});
And catching it also super simple!
// Old way
Try{
await SomeTask();
} Catch(Exception e) {
// catch code
}
// New way
SetupSnapExit(SomeTask(), (response) => {
// catch code
});
To make this work you will need to define a return point for SnapExit. This is made easy by using the ExitManager class!
public class SnapExitReturnPoint : ExitManager<ResponseData> // can be inherited from or instantiated
{
public async Task ThisCanBeAnyPointOfCode() {
SetupSnapExit(task, (response) => { // response is of type ResponseData
// any catch code goes here
});
}
}
Also look at the example project to see how you can turn SnapExit into a blazingly fast middleware for ASP.NET Core api!
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
-
net9.0
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated | |
---|---|---|---|
3.0.1 | 238 | 4/3/2025 | |
3.0.0 | 189 | 3/28/2025 | |
2.2.6 | 521 | 3/25/2025 | |
2.2.5 | 535 | 3/25/2025 | |
2.2.4 | 525 | 3/25/2025 | |
2.2.3 | 526 | 3/25/2025 | |
2.2.2 | 531 | 3/24/2025 | |
2.2.1 | 521 | 3/24/2025 | |
2.2.0 | 463 | 3/24/2025 | |
2.1.1 | 204 | 3/23/2025 | |
2.0.1 | 206 | 3/22/2025 | |
2.0.0 | 206 | 3/22/2025 | |
1.1.0 | 204 | 3/17/2025 | |
1.0.3 | 202 | 3/17/2025 | |
1.0.1 | 196 | 3/17/2025 | |
1.0.0 | 198 | 3/17/2025 |