SnapExit 3.0.1

Additional Details

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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SnapExit" Version="3.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SnapExit" Version="3.0.1" />
                    
Directory.Packages.props
<PackageReference Include="SnapExit" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SnapExit --version 3.0.1
                    
#r "nuget: SnapExit, 3.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SnapExit@3.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SnapExit&version=3.0.1
                    
Install as a Cake Addin
#tool nuget:?package=SnapExit&version=3.0.1
                    
Install as a Cake Tool

Snap exit 3.0.0

NuGet NuGet

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.1 is deprecated because it is no longer maintained and has critical bugs.
3.0.0 189 3/28/2025 3.0.0 is deprecated because it is no longer maintained and has critical bugs.
2.2.6 521 3/25/2025 2.2.6 is deprecated because it is no longer maintained and has critical bugs.
2.2.5 535 3/25/2025 2.2.5 is deprecated because it is no longer maintained and has critical bugs.
2.2.4 525 3/25/2025 2.2.4 is deprecated because it is no longer maintained and has critical bugs.
2.2.3 526 3/25/2025 2.2.3 is deprecated because it is no longer maintained and has critical bugs.
2.2.2 531 3/24/2025 2.2.2 is deprecated because it is no longer maintained and has critical bugs.
2.2.1 521 3/24/2025 2.2.1 is deprecated because it is no longer maintained and has critical bugs.
2.2.0 463 3/24/2025 2.2.0 is deprecated because it is no longer maintained and has critical bugs.
2.1.1 204 3/23/2025 2.1.1 is deprecated because it is no longer maintained and has critical bugs.
2.0.1 206 3/22/2025 2.0.1 is deprecated because it is no longer maintained and has critical bugs.
2.0.0 206 3/22/2025 2.0.0 is deprecated because it is no longer maintained and has critical bugs.
1.1.0 204 3/17/2025 1.1.0 is deprecated because it is no longer maintained and has critical bugs.
1.0.3 202 3/17/2025 1.0.3 is deprecated because it is no longer maintained and has critical bugs.
1.0.1 196 3/17/2025 1.0.1 is deprecated because it is no longer maintained and has critical bugs.
1.0.0 198 3/17/2025 1.0.0 is deprecated because it is no longer maintained and has critical bugs.