PollWatcher 1.0.0
PollWatcher provides a way to register handler delegates to poll-based monitoring solutions.
This enables event-driven development in scenarios where events are not provided and cannot easily be added.
Possible use-cases include: monitoring responses from an API, creating a recurring database task, polling a remote file server for changes, etc.
Built leveraging the System.Reactive namespace
Install-Package PollWatcher -Version 1.0.0
dotnet add package PollWatcher --version 1.0.0
<PackageReference Include="PollWatcher" Version="1.0.0" />
paket add PollWatcher --version 1.0.0
#r "nuget: PollWatcher, 1.0.0"
// Install PollWatcher as a Cake Addin
#addin nuget:?package=PollWatcher&version=1.0.0
// Install PollWatcher as a Cake Tool
#tool nuget:?package=PollWatcher&version=1.0.0
PollWatcher
PollWatcher provides a way to register handler delegates to poll-based monitoring solutions.
This enables event-driven development in scenarios where events are not provided and cannot easily be added.
Possible use-cases include: polling a remote file server for changes, monitoring responses from an API, creating a recurring database task, etc.
Built leveraging the System.Reactive namespace
Example (C# 9.0 syntax):
internal static class Program
{
private static void Main()
{
using var watcher = new PollWatcher<DateTime>(GetDate, interval, PrintDate, PrintException);
// using var asyncWatcher = new AsyncPollWatcher<DateTime>(GetDateAsync, interval, PrintDate, PrintException);
Thread.Sleep(5000);
}
// Returns a value that changes over time but must be retrieved synchronously
// In this case, it's the time
private static DateTime GetDate() => DateTime.Now;
// Returns a value that changes over time but must be retrieved asynchronously
// In this case, it's the time
private static async Task<DateTime> GetDateAsync() => await Task.Run(() => DateTime.Now);
//Specifies polling should occur every .001ms (if possible)
private static TimeSpan interval = TimeSpan.FromMilliseconds(.001);
// "Does stuff" with the data retrieved from polling
// In this case, we print it to the console
private static void PrintDate(DateTime dateTime) => Console.WriteLine(dateTime.ToString("O"));
// "Does stuff" with exceptions raised during polling
// In this case, we print it to the console
private static void PrintException(Exception exception) => Console.WriteLine($"Exception!!!\t{exception.Message}");
}
PollWatcher
PollWatcher provides a way to register handler delegates to poll-based monitoring solutions.
This enables event-driven development in scenarios where events are not provided and cannot easily be added.
Possible use-cases include: polling a remote file server for changes, monitoring responses from an API, creating a recurring database task, etc.
Built leveraging the System.Reactive namespace
Example (C# 9.0 syntax):
internal static class Program
{
private static void Main()
{
using var watcher = new PollWatcher<DateTime>(GetDate, interval, PrintDate, PrintException);
// using var asyncWatcher = new AsyncPollWatcher<DateTime>(GetDateAsync, interval, PrintDate, PrintException);
Thread.Sleep(5000);
}
// Returns a value that changes over time but must be retrieved synchronously
// In this case, it's the time
private static DateTime GetDate() => DateTime.Now;
// Returns a value that changes over time but must be retrieved asynchronously
// In this case, it's the time
private static async Task<DateTime> GetDateAsync() => await Task.Run(() => DateTime.Now);
//Specifies polling should occur every .001ms (if possible)
private static TimeSpan interval = TimeSpan.FromMilliseconds(.001);
// "Does stuff" with the data retrieved from polling
// In this case, we print it to the console
private static void PrintDate(DateTime dateTime) => Console.WriteLine(dateTime.ToString("O"));
// "Does stuff" with exceptions raised during polling
// In this case, we print it to the console
private static void PrintException(Exception exception) => Console.WriteLine($"Exception!!!\t{exception.Message}");
}
Dependencies
-
.NETFramework 4.6
- System.Reactive (>= 4.4.1)
-
.NETFramework 4.6.1
- System.Reactive (>= 4.4.1)
-
.NETStandard 2.0
- System.Reactive (>= 4.4.1)
-
net5.0
- System.Reactive (>= 4.4.1)
Used By
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version History
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 62 | 1/20/2021 |