NetcodeHub.Packages.Components.BackgroundTaskStopper 1.0.2

dotnet add package NetcodeHub.Packages.Components.BackgroundTaskStopper --version 1.0.2                
NuGet\Install-Package NetcodeHub.Packages.Components.BackgroundTaskStopper -Version 1.0.2                
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="NetcodeHub.Packages.Components.BackgroundTaskStopper" Version="1.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NetcodeHub.Packages.Components.BackgroundTaskStopper --version 1.0.2                
#r "nuget: NetcodeHub.Packages.Components.BackgroundTaskStopper, 1.0.2"                
#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.
// Install NetcodeHub.Packages.Components.BackgroundTaskStopper as a Cake Addin
#addin nuget:?package=NetcodeHub.Packages.Components.BackgroundTaskStopper&version=1.0.2

// Install NetcodeHub.Packages.Components.BackgroundTaskStopper as a Cake Tool
#tool nuget:?package=NetcodeHub.Packages.Components.BackgroundTaskStopper&version=1.0.2                

NetcodeHub.Packages.Components.BackgroundTaskStopper

Description

Introducing NetcodeHubTaskManager – a robust and efficient component for managing background tasks in your Blazor applications. With this package, you can ensure that any ongoing background operations are promptly canceled when a user navigates away from the component, freeing up resources and improving the responsiveness of your application. Say goodbye to lingering tasks and hello to streamlined performance with the NetcodeHubTaskManager.

Release Notes

Version 1.0.0

Initial Release:

  • Background Task Cancellation: Automatically cancels background tasks when the user navigates away from the component, ensuring that your application remains efficient and responsive.
  • Easy Integration: Seamlessly integrates into your existing Blazor components with minimal setup.
  • Resource Management: Efficiently manages and disposes of CancellationTokenSource to prevent memory leaks and ensure optimal performance.
  • Simple API: Provides a straightforward API to monitor and cancel background tasks with ease.

Usage Example:

@using NetcodeHub.Packages.Components.BackgroundTaskStopper
@inject HttpClient Http
@inherits NetcodeHubTaskManager
@code{
   protected override async Task OnInitializedAsync()
   {
       forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("https://localhost:9888/weather", ComponentMonitor());
   }
 }

Handling Code In Different File

using Microsoft.AspNetCore.Components;
using NetcodeHub.Packages.Components.BackgroundTaskStopper;

public class YourComponent : NetcodeHubTaskManager
{
    protected override async Task OnInitializedAsync()
    {
        var token = ComponentMonitor();
        try
        {
            await SomeLongRunningTask(token);
        }
        catch (OperationCanceledException)
        {
            // Handle task cancellation
        }
    }

    private async Task SomeLongRunningTask(CancellationToken token)
    {
        // Your long-running task logic here
    }
}

Handling With Same Component Name as Class

partial class Weather: NetcodeHubTaskManager
{
    private WeatherForecast[]? forecasts;
    [Inject] public HttpClient HttpClient { get; set; } = new();
    protected override async Task OnInitializedAsync()
    {
        forecasts = await HttpClient.GetFromJsonAsync<WeatherForecast[]>("https://localhost:9888/weather", ComponentMonitor());
    }
}

Inherit the Class in the Component

@page "/weather"
@using NetcodeHub.Packages.Components.BackgroundTaskStopper
@inherits NetcodeHubTaskManager 
<PageTitle>Weather</PageTitle>

Enhance your Blazor applications with the reliability and efficiency of NetcodeHubTaskManager. Download the package now and experience the difference!

Here's a follow-up section to encourage engagement and support for Netcode-Hub:

🌟 Get in touch with Netcode-Hub! 📫

  1. GitHub: Explore Repositories 🌐
  2. Twitter: Stay Updated 🐦
  3. Facebook: Connect Here 📘
  4. LinkedIn: Professional Network 🔗
  5. Email: Email: [email protected] 📧

☕️ If you've found value in Netcode-Hub's work, consider supporting the channel with a coffee!

  1. Buy Me a Coffee: Support Netcode-Hub ☕️
  2. Patreon: Support on Patreon 🌟
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. 
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
1.0.2 110 6/28/2024

Release Notes
Version 1.0.0
Initial Release:

Background Task Cancellation: Automatically cancels background tasks when the user navigates away from the component, ensuring that your application remains efficient and responsive.
Easy Integration: Seamlessly integrates into your existing Blazor components with minimal setup.
Resource Management: Efficiently manages and disposes of CancellationTokenSource to prevent memory leaks and ensure optimal performance.
Simple API: Provides a straightforward API to monitor and cancel background tasks with ease.