JsTimers 1.0.39

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

// Install JsTimers as a Cake Tool
#tool nuget:?package=JsTimers&version=1.0.39                

Project logo

Codefactor stats AppVeyor build status AppVeyor build status

JavaScript-style timers for .NET

Library offers simple API which mimics behaviour of NodeJS/Browser functions available in JavaScript, such as

  • SetTimeout
  • SetInterval
  • SetImmediate
  • ClearTimeout
  • ClearInterval
  • ClearImmediate

Original behaviour is closer to NodeJS (Returns objects instead of numbers, has ability to keep application running, et cetera) and is replicated as much as possible inside of the CLR

Documentation

For the full guide on the package functionality, make sure to check out the docs

Installation

Package manager console

Install-Package JsTimers

.NET CLI

dotnet add package JsTimers

Usage

All methods of library's public API are located inside JsTimers.TimerManager therefore, explanations below will not contain this type as prefix to presented method

For most cases it is easier to include using static directive in your code as shown below:

using static JsTimers.TimerManager;

Simple timer

To create basic timer, which will be fired once after specified delay, use SetTimeout method:

SetTimeout(() => {
  Console.WriteLine("Hello, JsTimers!");
}, 1000);

This will issue a timeout of 1 second and then execute a given callback

Cancelling timers

All methods mentioned above actually return objects which represent timers. These objects could be assigned to a variable for further actions, such as cancelling:

Timeout timeout = SetTimeout(() => {
  Console.WriteLine("This callback will not fire");
}, 1000);
ClearTimeout(timeout);

Important

Do not use this library to time execution of actions which require very high precision. Library runs internal loop and processes all active timers one by one, this might sometimes cause overhead of up to 30ms, therefore it works fine in most cases when you build general purpose software, but if you want to build an atomic clock with that, I have bad news for you

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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 was computed.  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. 
.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 was computed. 
.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.
  • .NETStandard 2.0

    • No dependencies.

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.39 1,062 3/26/2022
1.0.38 425 3/26/2022
1.0.37 446 9/23/2021