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
<PackageReference Include="NetcodeHub.Packages.Components.BackgroundTaskStopper" Version="1.0.2" />
paket add NetcodeHub.Packages.Components.BackgroundTaskStopper --version 1.0.2
#r "nuget: NetcodeHub.Packages.Components.BackgroundTaskStopper, 1.0.2"
// 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! 📫
- GitHub: Explore Repositories 🌐
- Twitter: Stay Updated 🐦
- Facebook: Connect Here 📘
- LinkedIn: Professional Network 🔗
- Email: Email: [email protected] 📧
☕️ If you've found value in Netcode-Hub's work, consider supporting the channel with a coffee!
- Buy Me a Coffee: Support Netcode-Hub ☕️
- Patreon: Support on Patreon 🌟
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. |
-
net8.0
- Microsoft.AspNetCore.Components.Web (>= 8.0.6)
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.