ktsu.IntervalAction 1.3.10

Prefix Reserved
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package ktsu.IntervalAction --version 1.3.10
                    
NuGet\Install-Package ktsu.IntervalAction -Version 1.3.10
                    
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="ktsu.IntervalAction" Version="1.3.10" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ktsu.IntervalAction" Version="1.3.10" />
                    
Directory.Packages.props
<PackageReference Include="ktsu.IntervalAction" />
                    
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 ktsu.IntervalAction --version 1.3.10
                    
#r "nuget: ktsu.IntervalAction, 1.3.10"
                    
#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 ktsu.IntervalAction@1.3.10
                    
#: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=ktsu.IntervalAction&version=1.3.10
                    
Install as a Cake Addin
#tool nuget:?package=ktsu.IntervalAction&version=1.3.10
                    
Install as a Cake Tool

ktsu.IntervalAction

A .NET library that provides a simple way to execute an action at a specified interval.

License NuGet Version NuGet Version NuGet Downloads GitHub commit activity GitHub contributors GitHub Actions Workflow Status

Introduction

IntervalAction is a .NET library that provides a simple and flexible way to execute an action at a specified interval. It offers precise control over execution timing, various interval types, and easy management of scheduled actions. Designed for scenarios where you need recurring tasks like polling, background processing, or timed updates.

Features

  • Flexible Timing: Execute actions at precise intervals
  • Interval Types: Choose between running intervals from last start or last completion
  • Configurable Polling: Fine-tune polling frequency for better performance
  • Immediate Execution: Option to execute actions immediately on start
  • Start/Stop Control: Easily pause and restart scheduled actions
  • Thread Safety: Safe for concurrent access from multiple threads
  • Low Overhead: Minimal resource usage during idle periods
  • Supports .NET 8.0 and .NET 9.0: Modern .NET support

Installation

Package Manager Console

Install-Package ktsu.IntervalAction

.NET CLI

dotnet add package ktsu.IntervalAction

Package Reference

<PackageReference Include="ktsu.IntervalAction" Version="x.y.z" />

Usage Examples

Basic Example

using ktsu.IntervalAction;

var intervalAction = IntervalAction.Start(new()
{
    Action = () => Console.WriteLine("Hello, World!"),
    ActionInterval = TimeSpan.FromSeconds(1),
    PollingInterval = TimeSpan.FromMilliseconds(100), // Optional, default is 1 second
    IntervalType = IntervalType.FromLastStart // Optional, default is FromLastCompletion
});

// An action will execute immediately and then every second
// outputting "Hello, World!" to the console until stopped

intervalAction.Stop();

// The action will no longer execute until you call Restart()

intervalAction.Restart();

Using FromLastCompletion Interval Type

using ktsu.IntervalAction;

var intervalAction = IntervalAction.Start(new()
{
    Action = () =>
    {
        Console.WriteLine($"Action started at: {DateTimeOffset.Now}");
        // Simulate a task that takes some time to complete
        Task.Delay(500).Wait();
        Console.WriteLine($"Action completed at: {DateTimeOffset.Now}");
    },
    ActionInterval = TimeSpan.FromSeconds(2),
    PollingInterval = TimeSpan.FromMilliseconds(100),
    IntervalType = IntervalType.FromLastCompletion // Waits until the action completes before starting the interval timer
});

// The action will execute immediately and then every 2 seconds after the previous execution completes

Handling Long-Running Tasks

using ktsu.IntervalAction;

var intervalAction = IntervalAction.Start(new()
{
    Action = async () =>
    {
        Console.WriteLine("Starting long-running task...");
        
        // Simulate a long-running task
        await Task.Delay(5000);
        
        Console.WriteLine("Long-running task completed");
    },
    ActionInterval = TimeSpan.FromSeconds(10),
    IntervalType = IntervalType.FromLastCompletion // Important for long-running tasks
});

// For cleanup when done
await Task.Delay(60000); // Run for 1 minute
intervalAction.Stop();

Dynamic Interval Adjustment

using ktsu.IntervalAction;

// Create with initial settings
var options = new IntervalActionOptions
{
    Action = () => Console.WriteLine($"Tick at {DateTime.Now}"),
    ActionInterval = TimeSpan.FromSeconds(5)
};

var intervalAction = IntervalAction.Start(options);

// Later, adjust the interval
await Task.Delay(20000); // After 20 seconds

intervalAction.Stop();
options.ActionInterval = TimeSpan.FromSeconds(1);
intervalAction.Restart();

Console.WriteLine("Interval changed to 1 second");

API Reference

IntervalAction Class

The main class for scheduling recurring actions.

Properties
Name Type Description
IsRunning bool Indicates if the action is currently scheduled to run
Options IntervalActionOptions The current options for this interval action
Methods
Name Parameters Return Type Description
Start IntervalActionOptions options IntervalAction Static factory method to create and start an interval action
Stop void Stops the scheduled action from running
Restart void Restarts a previously stopped action
Dispose void Cleans up resources and stops the action

IntervalActionOptions Class

Configuration options for an interval action.

Properties
Name Type Description
Action Action The action to execute at intervals (required)
ActionInterval TimeSpan The interval between executions (required)
PollingInterval TimeSpan How frequently to check if action should run (optional, default 1 second)
IntervalType IntervalType Determines how intervals are measured (optional, default FromLastCompletion)

IntervalType Enum

Defines how the interval is measured.

Value Description
FromLastCompletion The interval starts after the action has completed
FromLastStart The interval starts when the action begins executing

Contributing

Contributions are welcome! Here's how you can help:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Please make sure to update tests as appropriate and adhere to the existing coding style.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Versioning

Check the CHANGELOG.md for detailed release notes and version changes.

Acknowledgements

Special thanks to all contributors and the .NET community for their support.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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 is compatible.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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.3.11-pre.1 53 2/17/2026
1.3.10 197 2/16/2026
1.3.10-pre.1 48 2/16/2026
1.3.9 96 2/14/2026
1.3.8 94 2/14/2026
1.3.8-pre.7 48 2/6/2026
1.3.8-pre.6 54 2/5/2026
1.3.8-pre.5 56 2/3/2026
1.3.8-pre.4 59 2/1/2026
1.3.8-pre.3 50 1/31/2026
1.3.8-pre.2 51 1/31/2026
1.3.8-pre.1 50 1/31/2026
1.3.7 116 1/30/2026
1.3.6 99 1/30/2026
1.3.6-pre.1 51 1/28/2026
1.3.5 97 1/27/2026
1.3.4 113 1/12/2026
1.3.4-pre.4 158 11/24/2025
1.3.4-pre.3 130 11/23/2025
1.3.4-pre.2 113 11/23/2025
Loading failed

## v1.3.10 (patch)

Changes since v1.3.9:

- Merge remote-tracking branch 'refs/remotes/origin/main' ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync .github\workflows\dotnet.yml ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync .github\workflows\dotnet.yml ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync .github\workflows\dotnet.yml ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync .github\workflows\dotnet.yml ([@ktsu[bot]](https://github.com/ktsu[bot]))

## v1.3.10-pre.1 (prerelease)

Changes since v1.3.9:

- Sync .github\workflows\dotnet.yml ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync .github\workflows\dotnet.yml ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync .github\workflows\dotnet.yml ([@ktsu[bot]](https://github.com/ktsu[bot]))

## v1.3.9 (patch)

Changes since v1.3.8:

- Remove legacy build scripts ([@matt-edmondson](https://github.com/matt-edmondson))

## v1.3.8 (patch)

Changes since v1.3.7:

- Sync .github\workflows\dotnet.yml ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync global.json ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Merge remote-tracking branch 'refs/remotes/origin/main' ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync scripts\update-winget-manifests.ps1 ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync scripts\update-winget-manifests.ps1 ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync scripts\PSBuild.psm1 ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync global.json ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Merge remote-tracking branch 'refs/remotes/origin/main' ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync scripts\PSBuild.psm1 ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync scripts\PSBuild.psm1 ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync global.json ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Merge remote-tracking branch 'refs/remotes/origin/main' ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync global.json ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Merge remote-tracking branch 'refs/remotes/origin/main' ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync global.json ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync COPYRIGHT.md ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Merge remote-tracking branch 'refs/remotes/origin/main' ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync scripts\PSBuild.psm1 ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync scripts\update-winget-manifests.ps1 ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync global.json ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync COPYRIGHT.md ([@ktsu[bot]](https://github.com/ktsu[bot]))

## v1.3.8-pre.7 (prerelease)

Changes since v1.3.8-pre.6:

- Merge remote-tracking branch 'refs/remotes/origin/main' ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync scripts\update-winget-manifests.ps1 ([@ktsu[bot]](https://github.com/ktsu[bot]))

## v1.3.8-pre.6 (prerelease)

Changes since v1.3.8-pre.5:

- Sync scripts\update-winget-manifests.ps1 ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync scripts\PSBuild.psm1 ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync global.json ([@ktsu[bot]](https://github.com/ktsu[bot]))

## v1.3.8-pre.5 (prerelease)

Changes since v1.3.8-pre.4:

- Merge remote-tracking branch 'refs/remotes/origin/main' ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync scripts\PSBuild.psm1 ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync scripts\PSBuild.psm1 ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync global.json ([@ktsu[bot]](https://github.com/ktsu[bot]))

## v1.3.8-pre.4 (prerelease)

Changes since v1.3.8-pre.3:

- Merge remote-tracking branch 'refs/remotes/origin/main' ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync global.json ([@ktsu[bot]](https://github.com/ktsu[bot]))

## v1.3.8-pre.3 (prerelease)

Changes since v1.3.8-pre.2:

- Merge remote-tracking branch 'refs/remotes/origin/main' ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync global.json ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync COPYRIGHT.md ([@ktsu[bot]](https://github.com/ktsu[bot]))

## v1.3.8-pre.2 (prerelease)

Changes since v1.3.8-pre.1:

- Merge remote-tracking branch 'refs/remotes/origin/main' ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync scripts\PSBuild.psm1 ([@ktsu[bot]](https://github.com/ktsu[bot]))

## v1.3.8-pre.1 (prerelease)

No significant changes detected since v1.3.8.

## v1.3.7 (patch)

Changes since v1.3.6:

- Add compatibility suppressions for new .NET versions and dynamic member types ([@matt-edmondson](https://github.com/matt-edmondson))

## v1.3.6 (patch)

Changes since v1.3.5:

- Remove .github\workflows\project.yml ([@matt-edmondson](https://github.com/matt-edmondson))
- Merge remote-tracking branch 'refs/remotes/origin/main' ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync global.json ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Merge remote-tracking branch 'refs/remotes/origin/main' ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync .github\workflows\dotnet.yml ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync .gitignore ([@ktsu[bot]](https://github.com/ktsu[bot]))

## v1.3.6-pre.1 (prerelease)

No significant changes detected since v1.3.6.

## v1.3.5 (patch)

Changes since v1.3.4:

- Migrate to dotnet 10 ([@matt-edmondson](https://github.com/matt-edmondson))

## v1.3.4 (patch)

Changes since v1.3.3:

- Remove caching configuration for .NET setup in workflow ([@matt-edmondson](https://github.com/matt-edmondson))
- Add CLAUDE.md for project guidance and documentation ([@matt-edmondson](https://github.com/matt-edmondson))

## v1.3.4-pre.4 (prerelease)

Changes since v1.3.4-pre.3:

- Sync scripts\update-winget-manifests.ps1 ([@ktsu[bot]](https://github.com/ktsu[bot]))

## v1.3.4-pre.3 (prerelease)

Changes since v1.3.4-pre.2:

- Sync .github\workflows\dotnet.yml ([@ktsu[bot]](https://github.com/ktsu[bot]))

## v1.3.4-pre.2 (prerelease)

Changes since v1.3.4-pre.1:

- Sync scripts\PSBuild.psm1 ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync .github\workflows\dotnet.yml ([@ktsu[bot]](https://github.com/ktsu[bot]))

## v1.3.4-pre.1 (prerelease)

No significant changes detected since v1.3.4.

## v1.3.3 (patch)

Changes since v1.3.2:

- Convert to PolySharp ([@Damon3000s](https://github.com/Damon3000s))

## v1.3.2 (patch)

Changes since v1.3.1:

- Add CompatibilitySuppressions.xml for .NET compatibility diagnostics and update exception handling in IntervalAction class. Introduce new tests for zero and negative intervals, and ensure Stop method is idempotent. ([@matt-edmondson](https://github.com/matt-edmondson))
- Add configuration files for package management and CI/CD workflows ([@matt-edmondson](https://github.com/matt-edmondson))
- Update configuration files and scripts for improved build and test processes ([@matt-edmondson](https://github.com/matt-edmondson))

## v1.3.2-pre.17 (prerelease)

Changes since v1.3.2-pre.16:

- Merge remote-tracking branch 'refs/remotes/origin/main' ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync scripts\PSBuild.psm1 ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync .editorconfig ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync .gitattributes ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync .gitignore ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync .mailmap ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync .runsettings ([@ktsu[bot]](https://github.com/ktsu[bot]))

## v1.3.2-pre.16 (prerelease)

Changes since v1.3.2-pre.15:

- Sync scripts\PSBuild.psm1 ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync .editorconfig ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync .gitattributes ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync .gitignore ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync .mailmap ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync .runsettings ([@ktsu[bot]](https://github.com/ktsu[bot]))

## v1.3.2-pre.15 (prerelease)

Changes since v1.3.2-pre.14:


## v1.3.2-pre.14 (prerelease)

Changes since v1.3.2-pre.13:


## v1.3.2-pre.13 (prerelease)

Changes since v1.3.2-pre.12:


## v1.3.2-pre.12 (prerelease)

Changes since v1.3.2-pre.11:


## v1.3.2-pre.11 (prerelease)

Changes since v1.3.2-pre.10:


## v1.3.2-pre.10 (prerelease)

Changes since v1.3.2-pre.9:


## v1.3.2-pre.9 (prerelease)

Changes since v1.3.2-pre.8:


## v1.3.2-pre.8 (prerelease)

Changes since v1.3.2-pre.7:


## v1.3.2-pre.7 (prerelease)

Changes since v1.3.2-pre.6:


## v1.3.2-pre.6 (prerelease)

Changes since v1.3.2-pre.5:


## v1.3.2-pre.5 (prerelease)

Changes since v1.3.2-pre.4:


## v1.3.2-pre.4 (prerelease)

Changes since v1.3.2-pre.3:


## v1.3.2-pre.3 (prerelease)

Changes since v1.3.2-pre.2:


## v1.3.2-pre.2 (prerelease)

Changes since v1.3.2-pre.1:


## v1.3.2-pre.1 (prerelease)

No significant changes detected since v1.3.2.

## v1.3.1 (patch)

Changes since v1.3.0:

- Remove Directory.Build.props and Directory.Build.targets files; add copyright notices to IntervalAction source files and tests; update variable declarations in tests for consistency. ([@matt-edmondson](https://github.com/matt-edmondson))
- Enhance documentation and update project SDK references. Improved the library description for clarity and added detailed features and usage examples in README. Updated project files to use the latest SDK versions. ([@matt-edmondson](https://github.com/matt-edmondson))

## v1.3.1-pre.2 (prerelease)

Changes since v1.3.1-pre.1:

- Sync .github\workflows\dotnet.yml ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync .editorconfig ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync .runsettings ([@ktsu[bot]](https://github.com/ktsu[bot]))

## v1.3.1-pre.1 (prerelease)

No significant changes detected since v1.3.1.

## v1.3.0 (minor)

Changes since v1.2.0:

- Add LICENSE template ([@matt-edmondson](https://github.com/matt-edmondson))

## v1.2.1-pre.2 (prerelease)

Changes since v1.2.1-pre.1:

- Sync scripts\make-version.ps1 ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync scripts\make-changelog.ps1 ([@ktsu[bot]](https://github.com/ktsu[bot]))

## v1.2.1-pre.1 (prerelease)

Changes since v1.2.0:

- Sync scripts\make-version.ps1 ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync scripts\make-changelog.ps1 ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync .editorconfig ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync .gitignore ([@ktsu[bot]](https://github.com/ktsu[bot]))
- Sync Directory.Build.targets ([@ktsu[bot]](https://github.com/ktsu[bot]))

## v1.2.0 (minor)

Changes since v1.1.0:

- [minor] Update README.md ([@matt-edmondson](https://github.com/matt-edmondson))
- Refactor IntervalAction constructor and Start method ([@matt-edmondson](https://github.com/matt-edmondson))

## v1.1.0 (major)

No significant changes detected since v0.1.0.

## v0.1.0 (minor)

- Refactor IntervalAction constructor and Start method ([@matt-edmondson](https://github.com/matt-edmondson))
- Initial commit ([@matt-edmondson](https://github.com/matt-edmondson))