🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

ExtendedTimer

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ExtendedTimer

Package Description

1.0.5
Source
NuGet
Version published
Maintainers
1
Created
Source

ExtendedTimer

A C# class that has extra functionality over System.Timer.Timers. This class does not use System.Timer.Timers internally, and instead relies on asynchronous programming.

Basic usage

ExtendedTimer timer = new();
timer.TickInterval = 4000; // every 4 seconds
timer.StartDelay = 2000; // wait 2 seconds before starting the tick interval
timer.TickOnStart = true; // immediately tick upon calling Start()
timer.TickOnStartIgnoreDelay = true; // ignore the start delay if TickOnStart is true

// listening for tick events
timer.OnTimerTick += (sender, e) =>
{
    Console.WriteLine($"timer has ticked {timer.TickCount} times");
	if (timer.TickCount > 10)
	{
        Console.WriteLine("pausing timer because it has ticked over 10 times");
		timer.Pause();
    }
};

// listening for state changes
timer.OnTimerStateChanged += (sender, state) =>
{
    Console.WriteLine("timer state has changed. new state: " + state);
	bool exampleCondition = true;
	if (state == ExtendedTimer.TimerState.Paused && exampleCondition)
	{
        Console.WriteLine("resuming timer because a condition was met.");
		timer.Resume();
    }
};

timer.OnTimerStop += (sender, e) =>
{
	Console.WriteLine("timer has stopped. i wonder why...");
    Console.WriteLine("time since timer has been started: " + new DateTime(timer.TimeSinceStart));
};

timer.Start();

Keywords

FAQs

Package last updated on 09 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts