bloomtom.NaiveProgress 1.0.0

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

// Install bloomtom.NaiveProgress as a Cake Tool
#tool nuget:?package=bloomtom.NaiveProgress&version=1.0.0                

NaiveProgress

Provides a non-threaded implementation of IProgress.

The canonical implementation of IProgress is Progress, which uses a SynchronizationContext if you have one, and the thread pool if you don't. ASP.NET Core, Console and Test applications don't. The result is your progress reports might end up coming in out-of-order.

NaiveProgress doesn't do anything fancy. No SynchronizationContext, no thread pool. All reports are passed along to an event in the order they are received.

Nuget Packages

Package Name Target Framework Version
NaiveProgress .NET Standard 2.0 NuGet

Usage

Whenever you need an IProgress, make a NaiveProgress<T> instead of a Progress<T>; it was designed to be a drop in replacement.

Proof of Concept

Consider this function which delays for a period of time, and frequently reports progress.

private static void Delay(TimeSpan t, IProgress<TimeSpan> progress)
{
	var sw = new System.Diagnostics.Stopwatch();
	sw.Start();

	while (sw.Elapsed < t)
	{
		System.Threading.Thread.Sleep(1);
		progress.Report(sw.Elapsed);
	}
}

Using the normal Progress implementation is as follows

var progress = new Progress<TimeSpan>((e) =>
{
	Console.WriteLine(e.Ticks);
});

Delay(TimeSpan.FromMilliseconds(20), progress);

The following is the entire real output from running the above in a console application.

12618
468586
69860
117134

Ouch. As you can see, the console writes are out-of-order. Otherwise you'd expect Ticks to always increase.

To get in-order reports, simply change Progress to NaiveProgress

var progress = new NaiveProgress<TimeSpan>((e) =>
{
	Console.WriteLine(e.Ticks);
});

Delay(TimeSpan.FromMilliseconds(20), progress);

The result:

12986
62947
78007
93076
108074
123171
138230
153266
168358
183371
198416
213470

Every event is handled, and they're handled in-order.

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.0 1,775 1/4/2019