https://github.com/yortw/yort.deadmanswitch
A reusable implementation of a dead man switch. A dead man switch 'activates' (causes something to happen) when some event hasn't occurred for a specified period of time. It is effectively a resetable timer.
https://github.com/yortw/yort.deadmanswitch
deadmanswitch net40 netstandard20 switch timer
Last synced: about 1 month ago
JSON representation
A reusable implementation of a dead man switch. A dead man switch 'activates' (causes something to happen) when some event hasn't occurred for a specified period of time. It is effectively a resetable timer.
- Host: GitHub
- URL: https://github.com/yortw/yort.deadmanswitch
- Owner: Yortw
- License: mit
- Created: 2017-08-31T23:31:36.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2024-11-07T07:16:57.000Z (7 months ago)
- Last Synced: 2025-04-17T11:54:34.773Z (about 2 months ago)
- Topics: deadmanswitch, net40, netstandard20, switch, timer
- Language: C#
- Homepage: https://yortw.github.io/Yort.DeadManSwitch/
- Size: 58.6 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Yort.DeadManSwitch
## What is it?
A reusable implementation of a dead man switch. A dead man switch 'activates' (causes something to happen) when some event hasn't occurred for a specified period of time. It is effectively a resetable timer.### When would I use it?
Any time you want to take some action because something else hasn't happened for a while, this includes but is not limited to;* Logging or sending an alert when you haven't received a (network or other) message for X minutes/hours.
* Performing a search x millseconds after the last key pressed in an auto-search/complete text field.
* Starting archive/optimisation processes when there's been no user activity for a while.[](https://github.com/Yortw/Yort.DeadManSwitch/blob/master/LICENSE)
[](https://ci.appveyor.com/project/Yortw/yort-deadmanswitch)
## Supported Platforms
Currently;* .Net Standard 1.2
* .Net Standard 2.0
* .Net 4.0+## Available on Nuget
```powershell
PM> Install-Package Yort.DeadManSwitch
```
[](https://www.nuget.org/packages/Yort.DeadManSwitch/)## How do I use it?
Create a switch passing the action to call when the switch activates, the delay before activation, and other settings to the constructor. Call the *Reset* method of the switch each time a regular event occurs. When *Reset* hasn't been called within the delay period specified, the switch will activate.
*See the demo console app in the repo for sample usage*
```c#
using Yort.DeadManSwitch;//This switch activates after 5 seconds on inactivity, and automatically
//resets itself after activation.
var dms = new DeadManSwitch(5000, () => Console.WriteLine("Switch activated!")), (reason) => Console.WriteLine("Reset because " + reason.ToString()), true);//Somewhere else in the code, in a code path that should execute regularly within 5 seconds
dms.Reset();//To stop the switch, dispose it.
dms.Dispose();
```