├── .gitignore ├── .nuget ├── NuGet.Config ├── NuGet.exe └── packages.config ├── Build ├── appveyor-deploy-docs.ps1 ├── build.ps1 ├── check-key.ps1 ├── keys.ps1 ├── keys │ ├── Rackspace.Threading.dev.net35.snk │ ├── Rackspace.Threading.dev.snk │ ├── Rackspace.Threading.net35.snk │ └── Rackspace.Threading.snk ├── push.ps1 └── version.ps1 ├── Docs.Threading.History ├── 1.0 │ ├── Docs.Threading.1.0.shfbproj │ └── packages.config ├── 1.1 │ ├── Docs.Threading.1.1.shfbproj │ └── packages.config ├── 2.0 │ ├── Docs.Threading.2.0.shfbproj │ └── packages.config └── Current │ ├── Docs.Threading.Current.shfbproj │ └── packages.config ├── Docs.Threading ├── Content │ ├── BreakingChangesPolicy.aml │ ├── License.aml │ ├── MSHelpViewerRoot.aml │ ├── UserGuide │ │ ├── Installation.aml │ │ └── UserGuide.aml │ └── Welcome.aml ├── Docs.Threading.net35-client.shfbproj ├── Docs.Threading.net40-client.shfbproj ├── Docs.Threading.net45.shfbproj ├── Docs.Threading.netcore45.shfbproj ├── Docs.Threading.portable-net40.shfbproj ├── Docs.Threading.portable-net45.shfbproj └── Threading.content ├── LICENSE ├── PublicAPI ├── dotnet │ ├── PublicAPI.Shipped.txt │ └── PublicAPI.Unshipped.txt ├── net35-client │ ├── PublicAPI.Shipped.txt │ └── PublicAPI.Unshipped.txt └── net40 │ ├── PublicAPI.Shipped.txt │ └── PublicAPI.Unshipped.txt ├── README.md ├── Rackspace.Threading.sln ├── Rackspace.Threading ├── CancellationTokenSourceExtensions.cs ├── CompletedTask.cs ├── CoreTaskExtensions.cs ├── DelayedTask.cs ├── IAsyncDisposable.cs ├── IProgress`1.cs ├── Microsoft │ └── Runtime │ │ └── CompilerServices │ │ ├── ConfiguredTaskAwaitable.cs │ │ ├── ConfiguredTaskAwaitable`1.cs │ │ ├── TaskAwaiter.cs │ │ ├── TaskAwaiter`1.cs │ │ └── YieldAwaitable.cs ├── NamespaceDoc.cs ├── ProgressChangedEventArgs`1.cs ├── Progress`1.cs ├── Properties │ └── AssemblyInfo.cs ├── Rackspace.Threading.net35-client.csproj ├── Rackspace.Threading.net40-client.csproj ├── Rackspace.Threading.net45.csproj ├── Rackspace.Threading.netcore45.csproj ├── Rackspace.Threading.portable-net40.csproj ├── Rackspace.Threading.portable-net45.csproj ├── StreamExtensions.cs ├── System │ ├── AwaitExtensions.cs │ ├── ExecutionContextLightup.cs │ ├── Lightup.cs │ ├── LightupServices.cs │ ├── LightupType.cs │ └── Runtime │ │ └── CompilerServices │ │ ├── AsyncMethodBuilderCore.cs │ │ ├── AsyncMethodTaskCache`1.cs │ │ ├── AsyncServices.cs │ │ ├── AsyncStateMachineAttribute.cs │ │ ├── AsyncTaskMethodBuilder.cs │ │ ├── AsyncTaskMethodBuilder`1.cs │ │ ├── AsyncVoidMethodBuilder.cs │ │ ├── IAsyncMethodBuilder.cs │ │ ├── IAsyncStateMachine.cs │ │ ├── ICriticalNotifyCompletion.cs │ │ ├── INotifyCompletion.cs │ │ ├── IteratorStateMachineAttribute.cs │ │ └── StateMachineAttribute.cs ├── TaskBlocks.cs ├── TaskCompletionSourceExtensions.cs ├── TunnelVisionLabs.Threading.nuspec ├── VoidResult.cs ├── WebRequestExtensions.cs ├── packages.Rackspace.Threading.net35-client.config ├── packages.Rackspace.Threading.net40-client.config ├── packages.Rackspace.Threading.net45.config ├── packages.Rackspace.Threading.netcore45.config ├── packages.Rackspace.Threading.portable-net40.config └── packages.Rackspace.Threading.portable-net45.config ├── Samples └── CSharpSamples │ ├── CSharpSamples.csproj │ ├── Properties │ └── AssemblyInfo.cs │ ├── TaskBlockUsing.cs │ ├── TaskBlockUsingWithResult.cs │ ├── TaskBlockWhileAsync.cs │ └── TaskBlockWhileAsyncCondition.cs ├── Tests └── UnitTest.RackspaceThreading │ ├── Properties │ └── AssemblyInfo.cs │ ├── TaskTestingBase.cs │ ├── TestAsyncAwait.cs │ ├── TestCancellationTokenSourceExtensions.cs │ ├── TestCompletedTask.cs │ ├── TestCoreTaskExtensions_Catch.cs │ ├── TestCoreTaskExtensions_Finally.cs │ ├── TestCoreTaskExtensions_Select.cs │ ├── TestCoreTaskExtensions_Then.cs │ ├── TestDelayedTask_Delay.cs │ ├── TestDelayedTask_WhenAll.cs │ ├── TestDelayedTask_WhenAny.cs │ ├── TestProgress.cs │ ├── TestStreamExtensions.cs │ ├── TestTaskBlocks_Using.cs │ ├── TestTaskBlocks_While.cs │ ├── TestWebRequestExtensions.cs │ ├── UnitTest.RackspaceThreading.net35-client.csproj │ ├── UnitTest.RackspaceThreading.net40-client.csproj │ ├── UnitTest.RackspaceThreading.net45.csproj │ ├── UnitTest.RackspaceThreading.portable-net40.csproj │ ├── UnitTest.RackspaceThreading.portable-net45.csproj │ ├── packages.UnitTest.RackspaceThreading.net35-client.config │ ├── packages.UnitTest.RackspaceThreading.net40-client.config │ ├── packages.UnitTest.RackspaceThreading.net45.config │ ├── packages.UnitTest.RackspaceThreading.portable-net40.config │ └── packages.UnitTest.RackspaceThreading.portable-net45.config ├── TunnelVisionLabs.Threading.UnitTest.ruleset ├── TunnelVisionLabs.Threading.ruleset ├── appveyor.yml └── stylecop.json /.gitignore: -------------------------------------------------------------------------------- 1 | # NuGet Packages Folder 2 | /packages/ 3 | 4 | # Build output 5 | obj/ 6 | bin/ 7 | Build/nuget/ 8 | 9 | # Visual Studio per-user files 10 | *.suo 11 | *.user 12 | TestResults/ 13 | 14 | # Roslyn IntelliSense Cache 15 | *.vs/ 16 | -------------------------------------------------------------------------------- /.nuget/NuGet.Config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.nuget/NuGet.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tunnelvisionlabs/dotnet-threading/3e99a9d13476a1e8224d81f282f3cedad143c1bc/.nuget/NuGet.exe -------------------------------------------------------------------------------- /.nuget/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /Build/appveyor-deploy-docs.ps1: -------------------------------------------------------------------------------- 1 | param ( 2 | [switch]$Debug 3 | ) 4 | 5 | If ($Debug) { 6 | $BuildConfig = 'Debug' 7 | } Else { 8 | $BuildConfig = 'Release' 9 | } 10 | 11 | $DocsPath = "..\Docs.Threading\bin\Help\netcore45\$BuildConfig" 12 | 13 | # make sure the script was run from the expected path 14 | If (!(Test-Path $DocsPath)) { 15 | $host.ui.WriteErrorLine('The script was run from an invalid working directory.') 16 | Exit 1 17 | } 18 | 19 | function Upload-Folder() { 20 | param([string]$LocalPath, [string]$ArtifactName) 21 | 22 | [Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.FileSystem') 23 | [System.IO.Compression.ZipFile]::CreateFromDirectory((Join-Path (pwd) $LocalPath), (Join-Path (pwd) $ArtifactName)) 24 | Push-AppveyorArtifact (Join-Path (pwd) $ArtifactName) 25 | } 26 | 27 | Upload-Folder -LocalPath "$DocsPath" -ArtifactName "docs.zip" 28 | -------------------------------------------------------------------------------- /Build/build.ps1: -------------------------------------------------------------------------------- 1 | param ( 2 | [switch]$Debug, 3 | [string]$VisualStudioVersion = "14.0", 4 | [switch]$NoDocs, 5 | [string]$Verbosity = "minimal", 6 | [string]$Logger, 7 | [switch]$InstallSHFB 8 | ) 9 | 10 | # build the solution 11 | $SolutionPath = "..\Rackspace.Threading.sln" 12 | 13 | # make sure the script was run from the expected path 14 | if (!(Test-Path $SolutionPath)) { 15 | $host.ui.WriteErrorLine('The script was run from an invalid working directory.') 16 | exit 1 17 | } 18 | 19 | . .\version.ps1 20 | 21 | If ($Debug) { 22 | $BuildConfig = 'Debug' 23 | } Else { 24 | $BuildConfig = 'Release' 25 | } 26 | 27 | If ($Version.Contains('-')) { 28 | $KeyConfiguration = 'Dev' 29 | } Else { 30 | $KeyConfiguration = 'Final' 31 | } 32 | 33 | If ($NoDocs -and -not $Debug) { 34 | $SolutionBuildConfig = $BuildConfig + 'NoDocs' 35 | } Else { 36 | $SolutionBuildConfig = $BuildConfig 37 | } 38 | 39 | # build the main project 40 | $nuget = '..\.nuget\NuGet.exe' 41 | 42 | if ($VisualStudioVersion -eq '4.0') { 43 | $msbuild = "$env:windir\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe" 44 | } Else { 45 | $msbuild = "${env:ProgramFiles(x86)}\MSBuild\$VisualStudioVersion\Bin\MSBuild.exe" 46 | } 47 | 48 | &$nuget 'restore' $SolutionPath 49 | 50 | If ($InstallSHFB) { 51 | # This is the NuGet package name for the SHFB package 52 | $SHFBPackageName = 'EWSoftware.SHFB' 53 | # This is the version according to the NuGet package itself 54 | $SHFBVersion = '2014.11.22.0' 55 | 56 | $SHFBPackagePath = "..\.shfb\$SHFBPackageName.$SHFBVersion.nupkg" 57 | If (-not (Test-Path $SHFBPackagePath)) { 58 | If (-not (Test-Path '..\.shfb')) { 59 | mkdir '..\.shfb' 60 | } 61 | 62 | # This is the release name on GitHub where the NuGet package is attached 63 | $SHFBRelease = 'v2014.11.22.0-beta' 64 | 65 | $SHFBInstallerSource = "https://github.com/tunnelvisionlabs/SHFB/releases/download/$SHFBRelease/$SHFBPackageName.$SHFBVersion.nupkg" 66 | Invoke-WebRequest $SHFBInstallerSource -OutFile $SHFBPackagePath 67 | If (-not $?) { 68 | $host.ui.WriteErrorLine('Failed to download the SHFB NuGet package') 69 | Exit $LASTEXITCODE 70 | } 71 | } 72 | 73 | $SHFBPackages = [System.IO.Path]::GetFullPath((Join-Path (pwd) '..\.shfb')) 74 | $SHFBPackagesUri = [System.Uri]$SHFBPackages 75 | Echo "$nuget 'install' 'EWSoftware.SHFB' -Version $SHFBVersion -OutputDirectory '..\packages' -Source $SHFBPackagesUri" 76 | &$nuget 'install' $SHFBPackageName -Version $SHFBVersion -OutputDirectory '..\packages' -Source $SHFBPackagesUri 77 | If (-not $?) { 78 | $host.ui.WriteErrorLine('Failed to install the SHFB NuGet package') 79 | Exit $LASTEXITCODE 80 | } 81 | 82 | $env:SHFBROOT = [System.IO.Path]::GetFullPath((Join-Path (pwd) "..\packages\$SHFBPackageName.$SHFBVersion\tools")) 83 | } 84 | 85 | If (-not $NoDocs) { 86 | If ((-not $env:SHFBROOT) -or (-not (Test-Path $env:SHFBROOT))) { 87 | $host.ui.WriteErrorLine('Could not locate Sandcastle Help File Builder') 88 | Exit 1 89 | } 90 | } 91 | 92 | If ($Logger) { 93 | $LoggerArgument = "/logger:$Logger" 94 | } 95 | 96 | &$msbuild '/nologo' '/m' '/nr:false' '/t:rebuild' $LoggerArgument "/verbosity:$Verbosity" "/p:Configuration=$SolutionBuildConfig" "/p:Platform=Any CPU" "/p:VisualStudioVersion=$VisualStudioVersion" "/p:KeyConfiguration=$KeyConfiguration" $SolutionPath 97 | if (-not $?) { 98 | $host.ui.WriteErrorLine('Build failed, aborting!') 99 | exit $LASTEXITCODE 100 | } 101 | 102 | # By default, do not create a NuGet package unless the expected strong name key files were used 103 | if (-not $SkipKeyCheck) { 104 | . .\keys.ps1 105 | 106 | foreach ($pair in $Keys.GetEnumerator()) { 107 | $assembly = Resolve-FullPath -Path "..\Rackspace.Threading\bin\$($pair.Key)\$BuildConfig\Rackspace.Threading.dll" 108 | # Run the actual check in a separate process or the current process will keep the assembly file locked 109 | powershell -Command ".\check-key.ps1 -Assembly '$assembly' -ExpectedKey '$($pair.Value)' -Build '$($pair.Key)'" 110 | if (-not $?) { 111 | Exit $LASTEXITCODE 112 | } 113 | } 114 | } 115 | 116 | if (-not (Test-Path 'nuget')) { 117 | mkdir "nuget" 118 | } 119 | 120 | # The NuGet packages reference XML documentation which is post-processed by SHFB. If the -NoDocs flag is specified, 121 | # these files are not created so packaging will fail. 122 | If (-not $NoDocs) { 123 | &$nuget 'pack' '..\Rackspace.Threading\TunnelVisionLabs.Threading.nuspec' '-OutputDirectory' 'nuget' '-Prop' "Configuration=$BuildConfig" '-Version' "$Version" '-Symbols' 124 | Exit $LASTEXITCODE 125 | } 126 | -------------------------------------------------------------------------------- /Build/check-key.ps1: -------------------------------------------------------------------------------- 1 | param( 2 | [string]$Assembly, 3 | [string]$ExpectedKey, 4 | [string]$Build = $null 5 | ) 6 | 7 | function Get-PublicKeyToken() { 8 | param([string]$assembly = $null) 9 | if ($assembly) { 10 | $bytes = $null 11 | $bytes = [System.Reflection.Assembly]::ReflectionOnlyLoadFrom($assembly).GetName().GetPublicKeyToken() 12 | if ($bytes) { 13 | $key = "" 14 | for ($i=0; $i -lt $bytes.Length; $i++) { 15 | $key += "{0:x2}" -f $bytes[$i] 16 | } 17 | 18 | $key 19 | } 20 | } 21 | } 22 | 23 | if (-not $Build) { 24 | $Build = $Assembly 25 | } 26 | 27 | $actual = Get-PublicKeyToken -assembly $Assembly 28 | if ($actual -ne $ExpectedKey) { 29 | $host.ui.WriteErrorLine("Invalid publicKeyToken for '$Build'; expected '$ExpectedKey' but found '$actual'") 30 | exit 1 31 | } 32 | -------------------------------------------------------------------------------- /Build/keys.ps1: -------------------------------------------------------------------------------- 1 | # Note: these values may only change during major release 2 | 3 | If ($Version.Contains('-')) { 4 | 5 | # Use the development keys 6 | $Keys = @{ 7 | 'net35-client' = 'bb62785d398726f0' 8 | 'net40-client' = '2c5e0ae13bddb49e' 9 | 'net45' = '2c5e0ae13bddb49e' 10 | 'netcore45' = '2c5e0ae13bddb49e' 11 | 'portable-net40' = '2c5e0ae13bddb49e' 12 | 'portable-net45' = '2c5e0ae13bddb49e' 13 | } 14 | 15 | } Else { 16 | 17 | # Use the final release keys 18 | $Keys = @{ 19 | 'net35-client' = 'd693b28384d1c375' 20 | 'net40-client' = 'fd26f941b2df1ee3' 21 | 'net45' = 'fd26f941b2df1ee3' 22 | 'netcore45' = 'fd26f941b2df1ee3' 23 | 'portable-net40' = 'fd26f941b2df1ee3' 24 | 'portable-net45' = 'fd26f941b2df1ee3' 25 | } 26 | 27 | } 28 | 29 | function Resolve-FullPath() { 30 | param([string]$Path) 31 | [System.IO.Path]::GetFullPath((Join-Path (pwd) $Path)) 32 | } 33 | -------------------------------------------------------------------------------- /Build/keys/Rackspace.Threading.dev.net35.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tunnelvisionlabs/dotnet-threading/3e99a9d13476a1e8224d81f282f3cedad143c1bc/Build/keys/Rackspace.Threading.dev.net35.snk -------------------------------------------------------------------------------- /Build/keys/Rackspace.Threading.dev.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tunnelvisionlabs/dotnet-threading/3e99a9d13476a1e8224d81f282f3cedad143c1bc/Build/keys/Rackspace.Threading.dev.snk -------------------------------------------------------------------------------- /Build/keys/Rackspace.Threading.net35.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tunnelvisionlabs/dotnet-threading/3e99a9d13476a1e8224d81f282f3cedad143c1bc/Build/keys/Rackspace.Threading.net35.snk -------------------------------------------------------------------------------- /Build/keys/Rackspace.Threading.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tunnelvisionlabs/dotnet-threading/3e99a9d13476a1e8224d81f282f3cedad143c1bc/Build/keys/Rackspace.Threading.snk -------------------------------------------------------------------------------- /Build/push.ps1: -------------------------------------------------------------------------------- 1 | . .\version.ps1 2 | 3 | If ($Version.EndsWith('-dev')) { 4 | $host.ui.WriteErrorLine("Cannot push development version '$Version' to NuGet.") 5 | Exit 1 6 | } 7 | 8 | ..\.nuget\NuGet.exe 'push' ".\nuget\TunnelVisionLabs.Threading.$Version.nupkg" 9 | -------------------------------------------------------------------------------- /Build/version.ps1: -------------------------------------------------------------------------------- 1 | $Version = "2.1.0-dev" 2 | -------------------------------------------------------------------------------- /Docs.Threading.History/1.0/Docs.Threading.1.0.shfbproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 7 | Debug 8 | AnyCPU 9 | 2.0 10 | {252da18a-bdb9-4d15-b5a9-63fa2b7f91a8} 11 | 1.9.9.0 12 | 14 | Docs.Threading 15 | Docs.Threading 16 | Docs.Threading.net45 17 | 18 | .NET Framework 3.5 19 | Threading API Reference 20 | en-US 21 | 22 | 23 | 24 | 25 | OnlyWarningsAndErrors 26 | Website 27 | True 28 | True 29 | False 30 | False 31 | True 32 | Standard 33 | Blank 34 | True 35 | VS2013 36 | False 37 | MemberName 38 | Threading API Reference 39 | AboveNamespaces 40 | API Reference 41 | Msdn 42 | Msdn 43 | True 44 | True 45 | Attributes, ExplicitInterfaceImplementations, InheritedMembers, InheritedFrameworkMembers, Protected, ProtectedInternalAsProtected, SealedProtected 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | VisualStudio11 60 | -1 61 | 100 62 | 100 63 | -1 64 | Threading API 65 | Tunnel Vision Laboratories, LLC 66 | Id 67 | 100 68 | VS 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | &lt%3ba href=&quot%3bhttps://github.com/tunnelvisionlabs/dotnet-threading&quot%3b&gt%3bThreading Library Home&lt%3b/a&gt%3b 80 | 2 81 | False 82 | ..\..\ 83 | 84 | 87 | 88 | .\bin\Help\Debug\ 89 | 90 | 91 | .\bin\Help\Release\ 92 | 93 | 94 | 95 | 96 | 97 | 98 | ..\..\packages\TaskParallelLibrary.1.0.2856.0\lib\Net35\System.Threading.dll 99 | True 100 | 101 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /Docs.Threading.History/1.0/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Docs.Threading.History/1.1/Docs.Threading.1.1.shfbproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 7 | Debug 8 | AnyCPU 9 | 2.0 10 | {665b3728-8eb8-491d-b685-5ff1cccde62e} 11 | 1.9.9.0 12 | 14 | Docs.Threading 15 | Docs.Threading 16 | Docs.Threading.net45 17 | 18 | .NET Framework 3.5 19 | Threading API Reference 20 | en-US 21 | 22 | 23 | 24 | 25 | OnlyWarningsAndErrors 26 | Website 27 | True 28 | True 29 | False 30 | False 31 | True 32 | Standard 33 | Blank 34 | True 35 | VS2013 36 | False 37 | MemberName 38 | Threading API Reference 39 | AboveNamespaces 40 | API Reference 41 | Msdn 42 | Msdn 43 | True 44 | True 45 | Attributes, ExplicitInterfaceImplementations, InheritedMembers, InheritedFrameworkMembers, Protected, ProtectedInternalAsProtected, SealedProtected 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | VisualStudio11 60 | -1 61 | 100 62 | 100 63 | -1 64 | Threading API 65 | Tunnel Vision Laboratories, LLC 66 | Id 67 | 100 68 | VS 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | &lt%3ba href=&quot%3bhttps://github.com/tunnelvisionlabs/dotnet-threading&quot%3b&gt%3bThreading Library Home&lt%3b/a&gt%3b 80 | 2 81 | False 82 | ..\..\ 83 | 84 | 87 | 88 | .\bin\Help\Debug\ 89 | 90 | 91 | .\bin\Help\Release\ 92 | 93 | 94 | 95 | 96 | 97 | 98 | ..\..\packages\TaskParallelLibrary.1.0.2856.0\lib\Net35\System.Threading.dll 99 | True 100 | 101 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /Docs.Threading.History/1.1/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Docs.Threading.History/2.0/Docs.Threading.2.0.shfbproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 7 | Debug 8 | AnyCPU 9 | 2.0 10 | {971275cf-04b4-4062-9487-516674838f48} 11 | 1.9.9.0 12 | 14 | Docs.Threading 15 | Docs.Threading 16 | Docs.Threading.net45 17 | 18 | .NET Framework 3.5 19 | Threading API Reference 20 | en-US 21 | 22 | 23 | 24 | 25 | OnlyWarningsAndErrors 26 | Website 27 | True 28 | True 29 | False 30 | False 31 | True 32 | Standard 33 | Blank 34 | True 35 | VS2013 36 | False 37 | MemberName 38 | Threading API Reference 39 | AboveNamespaces 40 | API Reference 41 | Msdn 42 | Msdn 43 | True 44 | True 45 | Attributes, ExplicitInterfaceImplementations, InheritedMembers, InheritedFrameworkMembers, Protected, ProtectedInternalAsProtected, SealedProtected 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | VisualStudio11 60 | -1 61 | 100 62 | 100 63 | -1 64 | Threading API 65 | Tunnel Vision Laboratories, LLC 66 | Id 67 | 100 68 | VS 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | &lt%3ba href=&quot%3bhttps://github.com/tunnelvisionlabs/dotnet-threading&quot%3b&gt%3bThreading Library Home&lt%3b/a&gt%3b 80 | 2 81 | False 82 | ..\..\ 83 | 84 | 87 | 88 | .\bin\Help\Debug\ 89 | 90 | 91 | .\bin\Help\Release\ 92 | 93 | 94 | 95 | 96 | 97 | 98 | ..\..\packages\TaskParallelLibrary.1.0.2856.0\lib\Net35\System.Threading.dll 99 | True 100 | 101 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /Docs.Threading.History/2.0/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Docs.Threading.History/Current/Docs.Threading.Current.shfbproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 7 | Debug 8 | AnyCPU 9 | 2.0 10 | {f6d21c32-671d-469e-b094-49794dff550f} 11 | 1.9.9.0 12 | 14 | Docs.Threading 15 | Docs.Threading 16 | Docs.Threading.net45 17 | 18 | .NET Framework 3.5 19 | Threading API Reference 20 | en-US 21 | 22 | 23 | 24 | OnlyWarningsAndErrors 25 | Website 26 | True 27 | True 28 | False 29 | False 30 | True 31 | Standard 32 | Blank 33 | True 34 | VS2013 35 | False 36 | MemberName 37 | Threading API Reference 38 | AboveNamespaces 39 | API Reference 40 | Msdn 41 | Msdn 42 | True 43 | True 44 | Attributes, ExplicitInterfaceImplementations, InheritedMembers, InheritedFrameworkMembers, Protected, ProtectedInternalAsProtected, SealedProtected 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | VisualStudio11 59 | -1 60 | 100 61 | 100 62 | -1 63 | Threading API 64 | Tunnel Vision Laboratories, LLC 65 | Id 66 | 100 67 | VS 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | &lt%3ba href=&quot%3bhttps://github.com/tunnelvisionlabs/dotnet-threading&quot%3b&gt%3bThreading Library Home&lt%3b/a&gt%3b 79 | 2 80 | False 81 | ..\..\ 82 | 83 | 86 | 87 | .\bin\Help\Debug\ 88 | 89 | 90 | .\bin\Help\Release\ 91 | 92 | 93 | 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /Docs.Threading.History/Current/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | -------------------------------------------------------------------------------- /Docs.Threading/Content/MSHelpViewerRoot.aml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Welcome to the Rackspace Threading API Reference 6 | 7 | 8 |
9 | 10 | Select a topic from the table of contents. 11 | 12 |
13 | 14 | 15 | 16 | 17 |
18 |
19 | -------------------------------------------------------------------------------- /Docs.Threading/Content/Welcome.aml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 6 | 7 | 8 | 9 | Welcome to the Rackspace Threading Library, a lightweight utility library designed to simplify 10 | the development of efficient, asynchronous code targeting .NET 3.5 and newer. 11 | 12 | 13 | 14 |
15 | Project Resources 16 | 17 | 18 | The following links go directly to the latest information available about the project. 19 | 20 | 21 | 22 | 23 | 24 | Getting Started: 25 | 26 | 27 | 28 | 29 | Latest Release: 30 | GitHub Releases 31 | Release notes for the latest release on GitHub 32 | https://github.com/tunnelvisionlabs/dotnet-threading/releases/latest 33 | 34 | 35 | 36 | 37 | 38 | Source Code: 39 | GitHub Repository 40 | Source code for the project on GitHub 41 | https://github.com/tunnelvisionlabs/dotnet-threading 42 | 43 | 44 | 45 | 46 | 47 | Documentation: 48 | API Documentation 49 | Documentation for the latest release hosted on GitHub Pages 50 | https://tunnelvisionlabs.github.io/dotnet-threading/docs-latest 51 | 52 | 53 | 54 | 55 | 56 | Issue Tracker: 57 | GitHub Issues 58 | Project issue tracker on GitHub Issues 59 | https://github.com/tunnelvisionlabs/dotnet-threading/issues 60 | 61 | 62 | 63 | 64 | 65 |
66 | 67 | 68 |
69 |
70 | -------------------------------------------------------------------------------- /Docs.Threading/Docs.Threading.net35-client.shfbproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 7 | Debug 8 | AnyCPU 9 | 2.0 10 | {a2d73067-50e8-42f8-aeb1-3b6bde900850} 11 | 1.9.9.0 12 | 14 | Docs.Threading 15 | Docs.Threading 16 | Docs.Threading.net35-client 17 | 18 | .NET Framework 3.5 19 | Threading API Reference 20 | en-US 21 | 22 | 23 | 24 | OnlyWarningsAndErrors 25 | Website 26 | True 27 | True 28 | False 29 | False 30 | True 31 | Standard 32 | Blank 33 | True 34 | VS2013 35 | False 36 | MemberName 37 | Threading API Reference 38 | AboveNamespaces 39 | API Reference 40 | Msdn 41 | Msdn 42 | True 43 | True 44 | Attributes, ExplicitInterfaceImplementations, InheritedMembers, InheritedFrameworkMembers, Protected, ProtectedInternalAsProtected, SealedProtected 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | VisualStudio11 59 | -1 60 | 100 61 | 100 62 | -1 63 | Threading API 64 | Tunnel Vision Laboratories, LLC 65 | Id 66 | 100 67 | VS 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | &lt%3ba href=&quot%3bhttps://github.com/tunnelvisionlabs/dotnet-threading&quot%3b&gt%3bThreading Library Home&lt%3b/a&gt%3b 82 | 2 83 | False 84 | 85 | 88 | 89 | .\bin\Help\net35-client\Debug\ 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | .\bin\Help\net35-client\Release\ 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | -------------------------------------------------------------------------------- /Docs.Threading/Docs.Threading.net40-client.shfbproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 7 | Debug 8 | AnyCPU 9 | 2.0 10 | {e0f959ce-80b6-4fac-bf98-fe04f0a09396} 11 | 1.9.9.0 12 | 14 | Docs.Threading 15 | Docs.Threading 16 | Docs.Threading.net40-client 17 | 18 | .NET Framework 4.0 19 | Threading API Reference 20 | en-US 21 | 22 | 23 | 24 | OnlyWarningsAndErrors 25 | Website 26 | True 27 | True 28 | False 29 | False 30 | True 31 | Standard 32 | Blank 33 | True 34 | VS2013 35 | False 36 | MemberName 37 | Threading API Reference 38 | AboveNamespaces 39 | API Reference 40 | Msdn 41 | Msdn 42 | True 43 | True 44 | Attributes, ExplicitInterfaceImplementations, InheritedMembers, InheritedFrameworkMembers, Protected, ProtectedInternalAsProtected, SealedProtected 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | VisualStudio11 59 | -1 60 | 100 61 | 100 62 | -1 63 | Threading API 64 | Tunnel Vision Laboratories, LLC 65 | Id 66 | 100 67 | VS 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | &lt%3ba href=&quot%3bhttps://github.com/tunnelvisionlabs/dotnet-threading&quot%3b&gt%3bThreading Library Home&lt%3b/a&gt%3b 95 | 2 96 | False 97 | 98 | 101 | 102 | .\bin\Help\net40-client\Debug\ 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | .\bin\Help\net40-client\Release\ 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | -------------------------------------------------------------------------------- /Docs.Threading/Docs.Threading.net45.shfbproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 7 | Debug 8 | AnyCPU 9 | 2.0 10 | {47b1188c-3aa9-470c-b8cb-244a028c2cdb} 11 | 1.9.9.0 12 | 14 | Docs.Threading 15 | Docs.Threading 16 | Docs.Threading.net45 17 | 18 | .NET Framework 4.5 19 | Threading API Reference 20 | en-US 21 | 22 | 23 | 24 | OnlyWarningsAndErrors 25 | Website 26 | True 27 | True 28 | False 29 | False 30 | True 31 | Standard 32 | Blank 33 | True 34 | VS2013 35 | False 36 | MemberName 37 | Threading API Reference 38 | AboveNamespaces 39 | API Reference 40 | Msdn 41 | Msdn 42 | True 43 | True 44 | Attributes, ExplicitInterfaceImplementations, InheritedMembers, InheritedFrameworkMembers, Protected, ProtectedInternalAsProtected, SealedProtected 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | VisualStudio11 59 | -1 60 | 100 61 | 100 62 | -1 63 | Threading API 64 | Tunnel Vision Laboratories, LLC 65 | Id 66 | 100 67 | VS 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | &lt%3ba href=&quot%3bhttps://github.com/tunnelvisionlabs/dotnet-threading&quot%3b&gt%3bThreading Library Home&lt%3b/a&gt%3b 90 | 2 91 | False 92 | 93 | 96 | 97 | .\bin\Help\net45\Debug\ 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | .\bin\Help\net45\Release\ 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | -------------------------------------------------------------------------------- /Docs.Threading/Docs.Threading.portable-net40.shfbproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 7 | Debug 8 | AnyCPU 9 | 2.0 10 | {e9efeccd-c484-4b4b-a6dd-8480570d1ee6} 11 | 1.9.9.0 12 | 14 | Docs.Threading 15 | Docs.Threading 16 | Docs.Threading.portable-net40 17 | 18 | .NET Portable Library 4.0 %28Legacy%29 19 | Threading API Reference 20 | en-US 21 | 22 | 23 | 24 | OnlyWarningsAndErrors 25 | Website 26 | True 27 | True 28 | False 29 | False 30 | True 31 | Standard 32 | Blank 33 | True 34 | VS2013 35 | False 36 | MemberName 37 | Threading API Reference 38 | AboveNamespaces 39 | API Reference 40 | Msdn 41 | Msdn 42 | True 43 | True 44 | Attributes, ExplicitInterfaceImplementations, InheritedMembers, InheritedFrameworkMembers, Protected, ProtectedInternalAsProtected, SealedProtected 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | VisualStudio11 59 | -1 60 | 100 61 | 100 62 | -1 63 | Threading API 64 | Tunnel Vision Laboratories, LLC 65 | Id 66 | 100 67 | VS 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | &lt%3ba href=&quot%3bhttps://github.com/tunnelvisionlabs/dotnet-threading&quot%3b&gt%3bThreading Library Home&lt%3b/a&gt%3b 95 | 2 96 | False 97 | 98 | 101 | 102 | .\bin\Help\portable-net40\Debug\ 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | .\bin\Help\portable-net40\Release\ 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | -------------------------------------------------------------------------------- /Docs.Threading/Docs.Threading.portable-net45.shfbproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 7 | Debug 8 | AnyCPU 9 | 2.0 10 | {70569826-141e-416d-b52b-edc9b5f4301b} 11 | 1.9.9.0 12 | 14 | Docs.Threading 15 | Docs.Threading 16 | Docs.Threading.portable-net45 17 | 18 | .NET Portable Library 4.5 19 | Threading API Reference 20 | en-US 21 | 22 | 23 | 24 | OnlyWarningsAndErrors 25 | Website 26 | True 27 | True 28 | False 29 | False 30 | True 31 | Standard 32 | Blank 33 | True 34 | VS2013 35 | False 36 | MemberName 37 | Threading API Reference 38 | AboveNamespaces 39 | API Reference 40 | Msdn 41 | Msdn 42 | True 43 | True 44 | Attributes, ExplicitInterfaceImplementations, InheritedMembers, InheritedFrameworkMembers, Protected, ProtectedInternalAsProtected, SealedProtected 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | VisualStudio11 59 | -1 60 | 100 61 | 100 62 | -1 63 | Threading API 64 | Tunnel Vision Laboratories, LLC 65 | Id 66 | 100 67 | VS 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | &lt%3ba href=&quot%3bhttps://github.com/tunnelvisionlabs/dotnet-threading&quot%3b&gt%3bThreading Library Home&lt%3b/a&gt%3b 90 | 2 91 | False 92 | 93 | 96 | 97 | .\bin\Help\portable-net45\Debug\ 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | .\bin\Help\portable-net45\Release\ 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | -------------------------------------------------------------------------------- /Docs.Threading/Threading.content: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) Tunnel Vision Laboratories, LLC. All rights reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | these files except in compliance with the License. You may obtain a copy of the 5 | License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software distributed 10 | under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 11 | CONDITIONS OF ANY KIND, either express or implied. See the License for the 12 | specific language governing permissions and limitations under the License. 13 | 14 | --- 15 | 16 | This project uses other open source projects, which are used under the terms 17 | of the following license(s). 18 | 19 | Rackspace Threading Library 20 | 21 | Copyright (c) Rackspace, US Inc. All rights reserved. 22 | 23 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 24 | these files except in compliance with the License. You may obtain a copy of the 25 | License at 26 | 27 | http://www.apache.org/licenses/LICENSE-2.0 28 | 29 | Unless required by applicable law or agreed to in writing, software distributed 30 | under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 31 | CONDITIONS OF ANY KIND, either express or implied. See the License for the 32 | specific language governing permissions and limitations under the License. 33 | 34 | Microsoft .NET Reference Source 35 | 36 | Copyright (c) Microsoft Corporation 37 | 38 | Permission is hereby granted, free of charge, to any person obtaining a copy 39 | of this software and associated documentation files (the "Software"), to deal 40 | in the Software without restriction, including without limitation the rights 41 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 42 | copies of the Software, and to permit persons to whom the Software is 43 | furnished to do so, subject to the following conditions: 44 | 45 | The above copyright notice and this permission notice shall be included in all 46 | copies or substantial portions of the Software. 47 | 48 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 49 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 50 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 51 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 52 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 53 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 54 | SOFTWARE. 55 | -------------------------------------------------------------------------------- /PublicAPI/dotnet/PublicAPI.Unshipped.txt: -------------------------------------------------------------------------------- 1 | AwaitExtensions 2 | Microsoft.Runtime.CompilerServices.ConfiguredTaskAwaitable 3 | Microsoft.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter 4 | Microsoft.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult() -> void 5 | Microsoft.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.IsCompleted.get -> bool 6 | Microsoft.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.OnCompleted(System.Action continuation) -> void 7 | Microsoft.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.UnsafeOnCompleted(System.Action continuation) -> void 8 | Microsoft.Runtime.CompilerServices.ConfiguredTaskAwaitable.GetAwaiter() -> Microsoft.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter 9 | Microsoft.Runtime.CompilerServices.ConfiguredTaskAwaitable 10 | Microsoft.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter 11 | Microsoft.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult() -> TResult 12 | Microsoft.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.IsCompleted.get -> bool 13 | Microsoft.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.OnCompleted(System.Action continuation) -> void 14 | Microsoft.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.UnsafeOnCompleted(System.Action continuation) -> void 15 | Microsoft.Runtime.CompilerServices.ConfiguredTaskAwaitable.GetAwaiter() -> Microsoft.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter 16 | Microsoft.Runtime.CompilerServices.TaskAwaiter 17 | Microsoft.Runtime.CompilerServices.TaskAwaiter.GetResult() -> void 18 | Microsoft.Runtime.CompilerServices.TaskAwaiter.IsCompleted.get -> bool 19 | Microsoft.Runtime.CompilerServices.TaskAwaiter.OnCompleted(System.Action continuation) -> void 20 | Microsoft.Runtime.CompilerServices.TaskAwaiter.UnsafeOnCompleted(System.Action continuation) -> void 21 | Microsoft.Runtime.CompilerServices.TaskAwaiter 22 | Microsoft.Runtime.CompilerServices.TaskAwaiter.GetResult() -> TResult 23 | Microsoft.Runtime.CompilerServices.TaskAwaiter.IsCompleted.get -> bool 24 | Microsoft.Runtime.CompilerServices.TaskAwaiter.OnCompleted(System.Action continuation) -> void 25 | Microsoft.Runtime.CompilerServices.TaskAwaiter.UnsafeOnCompleted(System.Action continuation) -> void 26 | Microsoft.Runtime.CompilerServices.YieldAwaitable 27 | Microsoft.Runtime.CompilerServices.YieldAwaitable.GetAwaiter() -> Microsoft.Runtime.CompilerServices.YieldAwaitable.YieldAwaiter 28 | Microsoft.Runtime.CompilerServices.YieldAwaitable.YieldAwaiter 29 | Microsoft.Runtime.CompilerServices.YieldAwaitable.YieldAwaiter.GetResult() -> void 30 | Microsoft.Runtime.CompilerServices.YieldAwaitable.YieldAwaiter.IsCompleted.get -> bool 31 | Microsoft.Runtime.CompilerServices.YieldAwaitable.YieldAwaiter.OnCompleted(System.Action continuation) -> void 32 | Microsoft.Runtime.CompilerServices.YieldAwaitable.YieldAwaiter.UnsafeOnCompleted(System.Action continuation) -> void 33 | static AwaitExtensions.ConfigureAwait(this System.Threading.Tasks.Task task, bool continueOnCapturedContext) -> Microsoft.Runtime.CompilerServices.ConfiguredTaskAwaitable 34 | static AwaitExtensions.ConfigureAwait(this System.Threading.Tasks.Task task, bool continueOnCapturedContext) -> Microsoft.Runtime.CompilerServices.ConfiguredTaskAwaitable 35 | static AwaitExtensions.GetAwaiter(this System.Threading.Tasks.Task task) -> Microsoft.Runtime.CompilerServices.TaskAwaiter 36 | static AwaitExtensions.GetAwaiter(this System.Threading.Tasks.Task task) -> Microsoft.Runtime.CompilerServices.TaskAwaiter 37 | static Rackspace.Threading.CoreTaskExtensions.Catch(this System.Threading.Tasks.Task task, System.Predicate filter, System.Func, TException, System.Threading.Tasks.Task> handler) -> System.Threading.Tasks.Task 38 | static Rackspace.Threading.CoreTaskExtensions.Catch(this System.Threading.Tasks.Task task, System.Predicate filter, System.Func, TException, TResult> handler) -> System.Threading.Tasks.Task 39 | static Rackspace.Threading.CoreTaskExtensions.Catch(this System.Threading.Tasks.Task task, System.Predicate filter, System.Action handler) -> System.Threading.Tasks.Task 40 | static Rackspace.Threading.CoreTaskExtensions.Catch(this System.Threading.Tasks.Task task, System.Predicate filter, System.Func handler) -> System.Threading.Tasks.Task 41 | static Rackspace.Threading.DelayedTask.Yield() -> Microsoft.Runtime.CompilerServices.YieldAwaitable -------------------------------------------------------------------------------- /PublicAPI/net40/PublicAPI.Unshipped.txt: -------------------------------------------------------------------------------- 1 | static Rackspace.Threading.CoreTaskExtensions.Catch(this System.Threading.Tasks.Task task, System.Predicate filter, System.Func, TException, System.Threading.Tasks.Task> handler) -> System.Threading.Tasks.Task 2 | static Rackspace.Threading.CoreTaskExtensions.Catch(this System.Threading.Tasks.Task task, System.Predicate filter, System.Func, TException, TResult> handler) -> System.Threading.Tasks.Task 3 | static Rackspace.Threading.CoreTaskExtensions.Catch(this System.Threading.Tasks.Task task, System.Predicate filter, System.Action handler) -> System.Threading.Tasks.Task 4 | static Rackspace.Threading.CoreTaskExtensions.Catch(this System.Threading.Tasks.Task task, System.Predicate filter, System.Func handler) -> System.Threading.Tasks.Task 5 | static Rackspace.Threading.DelayedTask.Yield() -> Microsoft.Runtime.CompilerServices.YieldAwaitable -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Threading Library for .NET 2 | 3 | [![Join the chat at https://gitter.im/tunnelvisionlabs/dotnet-threading](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/tunnelvisionlabs/dotnet-threading?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 4 | 5 | [![Build status](https://ci.appveyor.com/api/projects/status/up5qifo34tharl4b/branch/master?svg=true)](https://ci.appveyor.com/project/sharwell/dotnet-threading/branch/master) 6 | 7 | [![codecov.io](https://codecov.io/github/tunnelvisionlabs/dotnet-threading/coverage.svg?branch=master)](https://codecov.io/github/tunnelvisionlabs/dotnet-threading?branch=master) 8 | 9 | This library provides utility classes to simplify writing asynchronous code targeting .NET 3.5 and newer. 10 | -------------------------------------------------------------------------------- /Rackspace.Threading/CompletedTask.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. 3 | 4 | namespace Rackspace.Threading 5 | { 6 | using System.Threading.Tasks; 7 | 8 | /// 9 | /// Provides static methods to create completed and instances. 10 | /// 11 | /// 12 | public static class CompletedTask 13 | { 14 | /// 15 | /// Gets a completed . 16 | /// 17 | /// A completed . 18 | public static Task Default 19 | { 20 | get 21 | { 22 | return FromResult(default(VoidResult)); 23 | } 24 | } 25 | 26 | /// 27 | /// Gets a completed with the specified result. 28 | /// 29 | /// The task result type. 30 | /// The result of the completed task. 31 | /// A completed , whose property returns the specified . 32 | public static Task FromResult(TResult result) 33 | { 34 | #if NET45PLUS 35 | return Task.FromResult(result); 36 | #else 37 | TaskCompletionSource completionSource = new TaskCompletionSource(); 38 | completionSource.SetResult(result); 39 | return completionSource.Task; 40 | #endif 41 | } 42 | 43 | /// 44 | /// Gets a canceled . 45 | /// 46 | /// A canceled . 47 | public static Task Canceled() 48 | { 49 | return Canceled(); 50 | } 51 | 52 | /// 53 | /// Gets a canceled . 54 | /// 55 | /// The task result type. 56 | /// A canceled . 57 | public static Task Canceled() 58 | { 59 | TaskCompletionSource completionSource = new TaskCompletionSource(); 60 | completionSource.SetCanceled(); 61 | return completionSource.Task; 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Rackspace.Threading/IAsyncDisposable.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. 3 | 4 | namespace Rackspace.Threading 5 | { 6 | using System; 7 | using System.Threading.Tasks; 8 | 9 | /// 10 | /// Provides a mechanism for asynchronously releasing unmanaged resources. 11 | /// 12 | public interface IAsyncDisposable : IDisposable 13 | { 14 | /// 15 | /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. 16 | /// 17 | /// 18 | /// This method should perform the same operation as , with the following 19 | /// key differences. 20 | /// 21 | /// The method should never be called from a finalizer. 22 | /// The method will not be called automatically from a using block, 23 | /// even when that block is located within an method. The 24 | /// methods provide support for the 25 | /// interface in a manner resembling the behavior proposed in 26 | /// IAsyncDisposable, using statements, and async/await. 27 | /// 28 | /// 29 | /// To prevent finalization of the object while an asynchronous dispose operation is ongoing, 30 | /// the returned by this method should retain a reference to the object 31 | /// until the operation is complete. 32 | /// 33 | /// 34 | /// A representing the asynchronous operation. 35 | Task DisposeAsync(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Rackspace.Threading/IProgress`1.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. 3 | 4 | #if NET40PLUS 5 | 6 | using System; 7 | using System.Runtime.CompilerServices; 8 | 9 | [assembly: TypeForwardedTo(typeof(IProgress<>))] 10 | 11 | #else 12 | 13 | namespace System 14 | { 15 | /// 16 | /// Defines a provider for progress updates. 17 | /// 18 | /// The type of progress update value. 19 | public interface IProgress 20 | { 21 | /// 22 | /// Reports a progress update. 23 | /// 24 | /// The value of the updated progress. 25 | void Report(T value); 26 | } 27 | } 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /Rackspace.Threading/Microsoft/Runtime/CompilerServices/ConfiguredTaskAwaitable.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. 3 | 4 | #if NET40PLUS && !NET45PLUS 5 | 6 | [assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(Microsoft.Runtime.CompilerServices.ConfiguredTaskAwaitable))] 7 | 8 | #else 9 | 10 | // NOTE: The reason this type does exist in the BCL System.Threading.Tasks contract is because we need to be able to 11 | // construct one of these in the AwaitExtensions class. The equivalent type in the current platform does not have an 12 | // accessible constructor, hence the AwaitExtensions would fail when run on platforms where System.Threading.Tasks gets 13 | // unified. 14 | namespace Microsoft.Runtime.CompilerServices 15 | { 16 | using System; 17 | using System.Diagnostics; 18 | using System.Runtime.CompilerServices; 19 | using System.Threading.Tasks; 20 | 21 | /// Provides an awaitable object that allows for configured awaits on . 22 | /// This type is intended for compiler use only. 23 | /// 24 | public struct ConfiguredTaskAwaitable 25 | { 26 | /// The task being awaited. 27 | private readonly ConfiguredTaskAwaiter _configuredTaskAwaiter; 28 | 29 | /// Initializes a new instance of the struct. 30 | /// The awaitable . 31 | /// 32 | /// to attempt to marshal the continuation back to the original context captured; 33 | /// otherwise, . 34 | /// 35 | internal ConfiguredTaskAwaitable(Task task, bool continueOnCapturedContext) 36 | { 37 | Debug.Assert(task != null, "Assertion failed: task != null"); 38 | _configuredTaskAwaiter = new ConfiguredTaskAwaiter(task, continueOnCapturedContext); 39 | } 40 | 41 | /// Gets an awaiter for this awaitable. 42 | /// The awaiter. 43 | public ConfiguredTaskAwaiter GetAwaiter() 44 | { 45 | return _configuredTaskAwaiter; 46 | } 47 | 48 | /// Provides an awaiter for a . 49 | /// This type is intended for compiler use only. 50 | public struct ConfiguredTaskAwaiter : ICriticalNotifyCompletion, INotifyCompletion 51 | { 52 | /// The task being awaited. 53 | private readonly Task _task; 54 | 55 | /// Whether to attempt marshaling back to the original context. 56 | private readonly bool _continueOnCapturedContext; 57 | 58 | /// Initializes a new instance of the struct. 59 | /// The to await. 60 | /// 61 | /// to attempt to marshal the continuation back to the original context captured; 62 | /// otherwise, . 63 | /// 64 | internal ConfiguredTaskAwaiter(Task task, bool continueOnCapturedContext) 65 | { 66 | Debug.Assert(task != null, "Assertion failed: task != null"); 67 | _task = task; 68 | _continueOnCapturedContext = continueOnCapturedContext; 69 | } 70 | 71 | /// Gets a value indicating whether the task being awaited is completed. 72 | /// This property is intended for compiler user rather than use directly in code. 73 | /// 74 | /// if the task being awaited is completed; otherwise, . 75 | /// 76 | /// The awaiter was not properly initialized. 77 | public bool IsCompleted 78 | { 79 | get 80 | { 81 | return _task.IsCompleted; 82 | } 83 | } 84 | 85 | /// 86 | /// Schedules the continuation onto the associated with this . 87 | /// 88 | /// The action to invoke when the await operation completes. 89 | /// 90 | /// If is . 91 | /// 92 | /// The awaiter was not properly initialized. 93 | /// This method is intended for compiler user rather than use directly in code. 94 | public void OnCompleted(Action continuation) 95 | { 96 | TaskAwaiter.OnCompletedInternal(_task, continuation, _continueOnCapturedContext); 97 | } 98 | 99 | /// 100 | /// Schedules the continuation onto the associated with this . 101 | /// 102 | /// The action to invoke when the await operation completes. 103 | /// 104 | /// If is . 105 | /// 106 | /// The awaiter was not properly initialized. 107 | /// This method is intended for compiler user rather than use directly in code. 108 | #if !SILVERLIGHT 109 | //// [SecurityCritical] 110 | #endif 111 | public void UnsafeOnCompleted(Action continuation) 112 | { 113 | TaskAwaiter.OnCompletedInternal(_task, continuation, _continueOnCapturedContext); 114 | } 115 | 116 | /// Ends the await on the completed . 117 | /// The awaiter was not properly initialized. 118 | /// The task was not yet completed. 119 | /// The task was canceled. 120 | /// The task completed in a state. 121 | public void GetResult() 122 | { 123 | TaskAwaiter.ValidateEnd(_task); 124 | } 125 | } 126 | } 127 | } 128 | 129 | #endif 130 | -------------------------------------------------------------------------------- /Rackspace.Threading/Microsoft/Runtime/CompilerServices/ConfiguredTaskAwaitable`1.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. 3 | 4 | #if NET40PLUS && !NET45PLUS 5 | 6 | [assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(Microsoft.Runtime.CompilerServices.ConfiguredTaskAwaitable<>))] 7 | 8 | #else 9 | 10 | // NOTE: The reason this type does exist in the BCL System.Threading.Tasks contract is because we need to be able to 11 | // construct one of these in the AwaitExtensions class. The equivalent type in the current platform does not have an 12 | // accessible constructor, hence the AwaitExtensions would fail when run on platforms where System.Threading.Tasks gets 13 | // unified. 14 | namespace Microsoft.Runtime.CompilerServices 15 | { 16 | using System; 17 | using System.Diagnostics; 18 | using System.Runtime.CompilerServices; 19 | using System.Threading.Tasks; 20 | 21 | /// 22 | /// Provides an awaitable object that allows for configured awaits on . 23 | /// 24 | /// This type is intended for compiler use only. 25 | /// The result type of the . 26 | /// 27 | public struct ConfiguredTaskAwaitable 28 | { 29 | /// The underlying awaitable on whose logic this awaitable relies. 30 | private readonly ConfiguredTaskAwaiter _configuredTaskAwaiter; 31 | 32 | /// Initializes a new instance of the struct. 33 | /// The awaitable . 34 | /// 35 | /// to attempt to marshal the continuation back to the original context captured; 36 | /// otherwise, . 37 | /// 38 | internal ConfiguredTaskAwaitable(Task task, bool continueOnCapturedContext) 39 | { 40 | _configuredTaskAwaiter = new ConfiguredTaskAwaiter(task, continueOnCapturedContext); 41 | } 42 | 43 | /// Gets an awaiter for this awaitable. 44 | /// The awaiter. 45 | public ConfiguredTaskAwaiter GetAwaiter() 46 | { 47 | return _configuredTaskAwaiter; 48 | } 49 | 50 | /// Provides an awaiter for a . 51 | /// This type is intended for compiler use only. 52 | public struct ConfiguredTaskAwaiter : ICriticalNotifyCompletion 53 | { 54 | /// The task being awaited. 55 | private readonly Task _task; 56 | 57 | /// Whether to attempt marshaling back to the original context. 58 | private readonly bool _continueOnCapturedContext; 59 | 60 | /// Initializes a new instance of the struct. 61 | /// The awaitable . 62 | /// 63 | /// to attempt to marshal the continuation back to the original context captured; 64 | /// otherwise, . 65 | /// 66 | internal ConfiguredTaskAwaiter(Task task, bool continueOnCapturedContext) 67 | { 68 | Debug.Assert(task != null, "Assertion failed: task != null"); 69 | _task = task; 70 | _continueOnCapturedContext = continueOnCapturedContext; 71 | } 72 | 73 | /// Gets a value indicating whether the task being awaited is completed. 74 | /// This property is intended for compiler user rather than use directly in code. 75 | /// 76 | /// if the task being awaited is completed; otherwise, . 77 | /// 78 | /// The awaiter was not properly initialized. 79 | public bool IsCompleted 80 | { 81 | get 82 | { 83 | return _task.IsCompleted; 84 | } 85 | } 86 | 87 | /// 88 | /// Schedules the continuation onto the associated with this . 89 | /// 90 | /// The action to invoke when the await operation completes. 91 | /// 92 | /// If is . 93 | /// 94 | /// The awaiter was not properly initialized. 95 | /// This method is intended for compiler user rather than use directly in code. 96 | public void OnCompleted(Action continuation) 97 | { 98 | TaskAwaiter.OnCompletedInternal(_task, continuation, _continueOnCapturedContext); 99 | } 100 | 101 | /// 102 | /// Schedules the continuation onto the associated with this . 103 | /// 104 | /// The action to invoke when the await operation completes. 105 | /// 106 | /// If is . 107 | /// 108 | /// The awaiter was not properly initialized. 109 | /// This method is intended for compiler user rather than use directly in code. 110 | #if !SILVERLIGHT 111 | //// [SecurityCritical] 112 | #endif 113 | public void UnsafeOnCompleted(Action continuation) 114 | { 115 | TaskAwaiter.OnCompletedInternal(_task, continuation, _continueOnCapturedContext); 116 | } 117 | 118 | /// Ends the await on the completed . 119 | /// The result of the completed . 120 | /// The awaiter was not properly initialized. 121 | /// The task was not yet completed. 122 | /// The task was canceled. 123 | /// The task completed in a state. 124 | public TResult GetResult() 125 | { 126 | TaskAwaiter.ValidateEnd(_task); 127 | return _task.Result; 128 | } 129 | } 130 | } 131 | } 132 | 133 | #endif 134 | -------------------------------------------------------------------------------- /Rackspace.Threading/Microsoft/Runtime/CompilerServices/TaskAwaiter`1.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. 3 | 4 | #if NET40PLUS && !NET45PLUS 5 | 6 | [assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(Microsoft.Runtime.CompilerServices.TaskAwaiter<>))] 7 | 8 | #else 9 | 10 | // NOTE: The reason this type does exist in the BCL System.Threading.Tasks contract is because we need to be able to 11 | // construct one of these in the AwaitExtensions class. The equivalent type in the current platform does not have an 12 | // accessible constructor, hence the AwaitExtensions would fail when run on platforms where System.Threading.Tasks gets 13 | // unified. 14 | namespace Microsoft.Runtime.CompilerServices 15 | { 16 | using System; 17 | using System.Diagnostics; 18 | using System.Runtime.CompilerServices; 19 | using System.Threading.Tasks; 20 | 21 | /// Provides an awaiter for awaiting a . 22 | /// This type is intended for compiler use only. 23 | /// The return type of the . 24 | /// 25 | public struct TaskAwaiter : ICriticalNotifyCompletion, INotifyCompletion 26 | { 27 | /// The task being awaited. 28 | private readonly Task _task; 29 | 30 | /// Initializes a new instance of the struct. 31 | /// The to be awaited. 32 | internal TaskAwaiter(Task task) 33 | { 34 | Debug.Assert(task != null, "Assertion failed: task != null"); 35 | _task = task; 36 | } 37 | 38 | /// Gets a value indicating whether the task being awaited is completed. 39 | /// This property is intended for compiler user rather than use directly in code. 40 | /// 41 | /// if the task being awaited is completed; otherwise, . 42 | /// 43 | /// The awaiter was not properly initialized. 44 | public bool IsCompleted 45 | { 46 | get 47 | { 48 | return _task.IsCompleted; 49 | } 50 | } 51 | 52 | /// 53 | /// Schedules the continuation onto the associated with this 54 | /// . 55 | /// 56 | /// The action to invoke when the await operation completes. 57 | /// 58 | /// If is . 59 | /// 60 | /// The awaiter was not properly initialized. 61 | /// This method is intended for compiler user rather than use directly in code. 62 | public void OnCompleted(Action continuation) 63 | { 64 | TaskAwaiter.OnCompletedInternal(_task, continuation, TaskAwaiter.ContinueOnCapturedContextDefault); 65 | } 66 | 67 | /// 68 | /// Schedules the continuation onto the associated with this 69 | /// . 70 | /// 71 | /// The action to invoke when the await operation completes. 72 | /// 73 | /// If is . 74 | /// 75 | /// The awaiter was not properly initialized. 76 | /// This method is intended for compiler user rather than use directly in code. 77 | #if !SILVERLIGHT 78 | ////[SecurityCritical] 79 | #endif 80 | public void UnsafeOnCompleted(Action continuation) 81 | { 82 | TaskAwaiter.OnCompletedInternal(_task, continuation, TaskAwaiter.ContinueOnCapturedContextDefault); 83 | } 84 | 85 | /// Ends the await on the completed . 86 | /// The result of the completed . 87 | /// The awaiter was not properly initialized. 88 | /// The task was not yet completed. 89 | /// The task was canceled. 90 | /// The task completed in a state. 91 | public TResult GetResult() 92 | { 93 | TaskAwaiter.ValidateEnd(_task); 94 | return _task.Result; 95 | } 96 | } 97 | } 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /Rackspace.Threading/Microsoft/Runtime/CompilerServices/YieldAwaitable.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. 3 | 4 | #if NET40PLUS && !NET45PLUS 5 | 6 | [assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(Microsoft.Runtime.CompilerServices.YieldAwaitable))] 7 | 8 | #else 9 | 10 | // NOTE: The reason this type does exist in the BCL System.Threading.Tasks contract is because we need to be able to 11 | // construct one of these in the AwaitExtensions class. The equivalent type in the current platform does not have an 12 | // accessible constructor, hence the AwaitExtensions would fail when run on platforms where System.Threading.Tasks gets 13 | // unified. 14 | namespace Microsoft.Runtime.CompilerServices 15 | { 16 | using System; 17 | using System.Runtime.CompilerServices; 18 | using System.Threading.Tasks; 19 | using Rackspace.Threading; 20 | 21 | /// Provides an awaitable context for switching into a target environment. 22 | /// This type is intended for compiler use only. 23 | /// 24 | public struct YieldAwaitable 25 | { 26 | /// Gets an awaiter for this . 27 | /// An awaiter for this awaitable. 28 | /// This method is intended for compiler user rather than use directly in code. 29 | public YieldAwaiter GetAwaiter() 30 | { 31 | // if not initialized properly, m_target will just be null 32 | return default(YieldAwaiter); 33 | } 34 | 35 | /// Provides an awaiter that switches into a target environment. 36 | /// This type is intended for compiler use only. 37 | public struct YieldAwaiter : ICriticalNotifyCompletion, INotifyCompletion 38 | { 39 | /// A completed task. 40 | private static readonly Task _completed = CompletedTask.FromResult(0); 41 | 42 | /// Gets a value indicating whether a yield is not required. 43 | /// This property is intended for compiler user rather than use directly in code. 44 | /// A value indicating whether a yield is not required. 45 | public bool IsCompleted 46 | { 47 | get 48 | { 49 | // yielding is always required for YieldAwaiter, hence false 50 | return false; 51 | } 52 | } 53 | 54 | /// Posts the back to the current context. 55 | /// The action to invoke asynchronously. 56 | /// The awaiter was not properly initialized. 57 | public void OnCompleted(Action continuation) 58 | { 59 | _completed.GetAwaiter().OnCompleted(continuation); 60 | } 61 | 62 | /// Posts the back to the current context. 63 | /// The action to invoke asynchronously. 64 | /// The awaiter was not properly initialized. 65 | ////[SecurityCritical] 66 | public void UnsafeOnCompleted(Action continuation) 67 | { 68 | _completed.GetAwaiter().UnsafeOnCompleted(continuation); 69 | } 70 | 71 | /// Ends the await operation. 72 | public void GetResult() 73 | { 74 | // NOP. It exists purely because the compiler pattern demands it. 75 | } 76 | } 77 | } 78 | } 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /Rackspace.Threading/NamespaceDoc.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. 3 | 4 | namespace Rackspace.Threading 5 | { 6 | using System.Runtime.CompilerServices; 7 | 8 | /// 9 | /// The namespace contains classes for simplifying the 10 | /// development of asynchronous code which supports .NET 3.5 and newer, without relying 11 | /// on . 12 | /// 13 | [CompilerGenerated] 14 | internal class NamespaceDoc 15 | { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Rackspace.Threading/ProgressChangedEventArgs`1.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. 3 | 4 | namespace Rackspace.Threading 5 | { 6 | using System; 7 | 8 | /// 9 | /// This class contains information for the event. 10 | /// 11 | /// 12 | /// Prior to .NET 4.5, the delegate included a 13 | /// constraint that the generic argument be derived from . This 14 | /// constraint prevents a direct back-port of the 15 | /// class to earlier frameworks, so the class is provided with 16 | /// a wrapper around the progress value reported by the 17 | /// event. 18 | /// 19 | /// The type representing the progress indicator. 20 | /// 21 | public class ProgressChangedEventArgs : EventArgs 22 | { 23 | /// 24 | /// This is the backing field for the property. 25 | /// 26 | private readonly T _progress; 27 | 28 | /// 29 | /// Initializes a new instance of the class 30 | /// with the specified progress. 31 | /// 32 | /// An instance of representing the current progress. 33 | public ProgressChangedEventArgs(T progress) 34 | { 35 | _progress = progress; 36 | } 37 | 38 | /// 39 | /// Gets the current progress. 40 | /// 41 | /// 42 | /// An instance of representing the current progress. 43 | /// 44 | public T Progress 45 | { 46 | get 47 | { 48 | return _progress; 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Rackspace.Threading/Progress`1.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. 3 | 4 | namespace Rackspace.Threading 5 | { 6 | using System; 7 | using System.Threading; 8 | 9 | /// 10 | /// Provides an that invokes callbacks for each reported progress value. 11 | /// 12 | /// 13 | /// Any handler provided to the constructor or event handlers registered with the 14 | /// event are invoked through a 15 | /// instance captured when the instance is constructed. If there is no current 16 | /// at the time of construction, the callbacks will be invoked 17 | /// on the . 18 | /// 19 | /// Specifies the type of the progress report value. 20 | public class Progress : IProgress 21 | { 22 | private static readonly SynchronizationContext DefaultSynchronizationContext = new SynchronizationContext(); 23 | 24 | private readonly SynchronizationContext _synchronizationContext; 25 | private readonly SendOrPostCallback _callback; 26 | private readonly Action _handler; 27 | 28 | /// 29 | /// Initializes a new instance of the class. 30 | /// 31 | public Progress() 32 | { 33 | _synchronizationContext = SynchronizationContext.Current ?? DefaultSynchronizationContext; 34 | _callback = Callback; 35 | } 36 | 37 | /// 38 | /// Initializes a new instance of the class with the specified callback. 39 | /// 40 | /// 41 | /// A handler to invoke for each reported progress value. This handler will be invoked in addition 42 | /// to any delegates registered with the event. Depending on the 43 | /// instance captured by the at 44 | /// construction, it is possible that this handler instance could be invoked concurrently with 45 | /// itself. 46 | /// 47 | public Progress(Action handler) 48 | : this() 49 | { 50 | _handler = handler; 51 | } 52 | 53 | /// 54 | /// Raised for each reported progress value. 55 | /// 56 | /// 57 | /// Handlers registered with this event will be invoked on the 58 | /// captured when the instance was constructed. 59 | /// 60 | public event EventHandler> ProgressChanged; 61 | 62 | /// 63 | /// 64 | /// Any handler provided to the constructor or event handlers registered with the 65 | /// event are invoked through a 66 | /// instance captured when the instance is constructed. If there is no current 67 | /// at the time of construction, the callbacks will be invoked 68 | /// on the . 69 | /// 70 | void IProgress.Report(T value) 71 | { 72 | OnReport(value); 73 | } 74 | 75 | /// 76 | /// Reports a progress change. 77 | /// 78 | /// The value of the updated progress. 79 | protected virtual void OnReport(T value) 80 | { 81 | if (_handler != null || ProgressChanged != null) 82 | _synchronizationContext.Post(_callback, value); 83 | } 84 | 85 | private void Callback(object state) 86 | { 87 | T value = (T)state; 88 | if (_handler != null) 89 | _handler(value); 90 | 91 | EventHandler> t = ProgressChanged; 92 | if (t != null) 93 | t(this, new ProgressChangedEventArgs(value)); 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /Rackspace.Threading/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. 3 | 4 | using System; 5 | using System.Reflection; 6 | using System.Runtime.InteropServices; 7 | 8 | // General Information about an assembly is controlled through the following 9 | // set of attributes. Change these attribute values to modify the information 10 | // associated with an assembly. 11 | [assembly: AssemblyTitle("Rackspace.Threading")] 12 | [assembly: AssemblyDescription("Utility library to simplify writing asynchronous code which supports .NET 3.5 and newer")] 13 | [assembly: AssemblyConfiguration("")] 14 | [assembly: AssemblyCompany("Tunnel Vision Laboratories, LLC")] 15 | [assembly: AssemblyProduct("TunnelVisionLabs.Threading")] 16 | [assembly: AssemblyCopyright("Copyright © Sam Harwell 2015")] 17 | [assembly: AssemblyTrademark("")] 18 | [assembly: AssemblyCulture("")] 19 | [assembly: CLSCompliant(true)] 20 | 21 | #if !PORTABLE 22 | // Setting ComVisible to false makes the types in this assembly not visible 23 | // to COM components. If you need to access a type in this assembly from 24 | // COM, set the ComVisible attribute to true on that type. 25 | [assembly: ComVisible(false)] 26 | #endif 27 | 28 | [assembly: AssemblyVersion("2.1.0.0")] 29 | [assembly: AssemblyFileVersion("2.1.0.0")] 30 | [assembly: AssemblyInformationalVersion("2.1.0-dev")] 31 | -------------------------------------------------------------------------------- /Rackspace.Threading/System/AwaitExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. 3 | 4 | #if NET40PLUS && !NET45PLUS 5 | 6 | using System.Runtime.CompilerServices; 7 | 8 | [assembly: TypeForwardedTo(typeof(AwaitExtensions))] 9 | 10 | #else 11 | 12 | using System; 13 | using System.Threading; 14 | using System.Threading.Tasks; 15 | using Microsoft.Runtime.CompilerServices; 16 | 17 | /// 18 | /// Provides extension methods for threading-related types. 19 | /// 20 | /// 21 | public static class AwaitExtensions 22 | { 23 | /// Gets an awaiter used to await this . 24 | /// The task to await. 25 | /// An awaiter instance. 26 | public static TaskAwaiter GetAwaiter(this Task task) 27 | { 28 | if (task == null) 29 | throw new ArgumentNullException("task"); 30 | 31 | return new TaskAwaiter(task); 32 | } 33 | 34 | /// Gets an awaiter used to await this . 35 | /// Specifies the type of data returned by the task. 36 | /// The task to await. 37 | /// An awaiter instance. 38 | public static TaskAwaiter GetAwaiter(this Task task) 39 | { 40 | if (task == null) 41 | throw new ArgumentNullException("task"); 42 | 43 | return new TaskAwaiter(task); 44 | } 45 | 46 | /// Creates and configures an awaitable object for awaiting the specified task. 47 | /// The task to be awaited. 48 | /// 49 | /// to automatically marshal back to the original call site's current 50 | /// or ; otherwise, . 51 | /// 52 | /// The instance to be awaited. 53 | public static ConfiguredTaskAwaitable ConfigureAwait(this Task task, bool continueOnCapturedContext) 54 | { 55 | if (task == null) 56 | throw new ArgumentNullException("task"); 57 | 58 | return new ConfiguredTaskAwaitable(task, continueOnCapturedContext); 59 | } 60 | 61 | /// Creates and configures an awaitable object for awaiting the specified task. 62 | /// The return type of the . 63 | /// The task to be awaited. 64 | /// 65 | /// to automatically marshal back to the original call site's current 66 | /// or ; otherwise, . 67 | /// 68 | /// The instance to be awaited. 69 | public static ConfiguredTaskAwaitable ConfigureAwait(this Task task, bool continueOnCapturedContext) 70 | { 71 | if (task == null) 72 | throw new ArgumentNullException("task"); 73 | 74 | return new ConfiguredTaskAwaitable(task, continueOnCapturedContext); 75 | } 76 | } 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /Rackspace.Threading/System/ExecutionContextLightup.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. 3 | 4 | #if !NET40PLUS 5 | 6 | // The reference source is missing documentation 7 | #pragma warning disable SA1600 // Elements must be documented 8 | 9 | namespace System 10 | { 11 | using System; 12 | using System.Reflection; 13 | 14 | internal class ExecutionContextLightup : Lightup 15 | { 16 | public static readonly ExecutionContextLightup Instance = new ExecutionContextLightup(null); 17 | private readonly object _executionContext; 18 | private Delegate _dispose; 19 | private Delegate _capture; 20 | private Delegate _run; 21 | private Delegate _createCopy; 22 | 23 | private ExecutionContextLightup(object executionContext) 24 | : base(LightupType.ExecutionContext) 25 | { 26 | _executionContext = executionContext; 27 | } 28 | 29 | protected override object GetInstance() 30 | { 31 | return _executionContext; 32 | } 33 | 34 | public ExecutionContextLightup Capture() 35 | { 36 | object executionContext; 37 | if (TryCall(ref _capture, "Capture", out executionContext) && executionContext != null) 38 | { 39 | return new ExecutionContextLightup(executionContext); 40 | } 41 | 42 | return null; 43 | } 44 | 45 | public ExecutionContextLightup CreateCopy() 46 | { 47 | object copy = Call(ref _createCopy, "CreateCopy"); 48 | 49 | return new ExecutionContextLightup(copy); 50 | } 51 | 52 | public void Run(ExecutionContextLightup executionContext, Action callback, object state) 53 | { 54 | if (LightupType.ExecutionContext == null || LightupType.ContextCallback == null) 55 | throw new PlatformNotSupportedException(); 56 | 57 | // Replace the Action with a ContextCallback 58 | Delegate contextCallback = LightupServices.ReplaceWith(callback, LightupType.ContextCallback); 59 | 60 | Type actionRepresentingSignature = typeof(Action<,,>).MakeGenericType(LightupType.ExecutionContext, LightupType.ContextCallback, typeof(object)); 61 | 62 | Delegate d = GetMethodAccessor(ref _run, actionRepresentingSignature, "Run"); 63 | d.DynamicInvoke(executionContext._executionContext, contextCallback, state); 64 | } 65 | 66 | public void Dispose() 67 | { 68 | TryCall(ref _dispose, "Dispose"); 69 | } 70 | } 71 | } 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /Rackspace.Threading/System/Lightup.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. 3 | 4 | #if !NET40PLUS 5 | 6 | // The reference source is missing documentation 7 | #pragma warning disable SA1600 // Elements must be documented 8 | 9 | namespace System 10 | { 11 | using System.Linq; 12 | using System.Reflection; 13 | using System.Threading; 14 | 15 | internal abstract class Lightup 16 | { 17 | private static readonly Type[] EmptyTypes = Type.EmptyTypes; 18 | private readonly Type _type; 19 | 20 | protected Lightup(Type type) 21 | { 22 | _type = type; 23 | } 24 | 25 | protected static T Create(params object[] parameters) 26 | { 27 | Type[] argumentTypes = parameters.Select(p => p.GetType()) 28 | .ToArray(); 29 | 30 | Func activator = CreateActivator(argumentTypes); 31 | 32 | return activator(parameters); 33 | } 34 | 35 | protected bool TryGet(ref Delegate storage, string propertyName, out T value) 36 | { 37 | return TryCall(ref storage, "get_" + propertyName, out value); 38 | } 39 | 40 | protected T Get(ref Delegate storage, string propertyName) 41 | { 42 | return Call(ref storage, "get_" + propertyName); 43 | } 44 | 45 | protected void Set(ref Delegate storage, string propertyName, T value) 46 | { 47 | Call(ref storage, "set_" + propertyName, value); 48 | } 49 | 50 | protected void Set(ref Delegate storage, TI instance, string propertyName, TV value) 51 | { 52 | Call(ref storage, instance, "set_" + propertyName, value); 53 | } 54 | 55 | protected bool TrySet(ref Delegate storage, TI instance, string propertyName, TV value) 56 | { 57 | return TryCall(ref storage, instance, "set_" + propertyName, value); 58 | } 59 | 60 | protected bool TryCall(ref Delegate storage, string methodName, out T returnValue) 61 | { 62 | Func method = GetMethodAccessor>(ref storage, methodName); 63 | if (method == null) 64 | { 65 | returnValue = default(T); 66 | return false; 67 | } 68 | 69 | returnValue = method(); 70 | return true; 71 | } 72 | 73 | protected T Call(ref Delegate storage, string methodName) 74 | { 75 | Func method = GetMethodAccessor>(ref storage, methodName); 76 | if (method == null) 77 | throw new InvalidOperationException(); 78 | 79 | return method(); 80 | } 81 | 82 | protected bool TryCall(ref Delegate storage, string methodName) 83 | { 84 | Action method = GetMethodAccessor(ref storage, methodName); 85 | if (method == null) 86 | return false; 87 | 88 | method(); 89 | return true; 90 | } 91 | 92 | protected bool TryCall(ref Delegate storage, TI instance, string methodName, TV parameter) 93 | { 94 | Action method = GetMethodAccessor>(ref storage, methodName, bindInstance: false); 95 | if (method == null) 96 | return false; 97 | 98 | method(instance, parameter); 99 | return true; 100 | } 101 | 102 | protected bool TryCall(ref Delegate storage, TI instance, string methodName, TV1 parameter1, TV2 parameter2) 103 | { 104 | Action method = GetMethodAccessor>(ref storage, methodName, bindInstance: false); 105 | if (method == null) 106 | return false; 107 | 108 | method(instance, parameter1, parameter2); 109 | return true; 110 | } 111 | 112 | protected void Call(ref Delegate storage, TI instance, string methodName, TV parameter) 113 | { 114 | Action method = GetMethodAccessor>(ref storage, methodName, bindInstance: false); 115 | if (method == null) 116 | throw new InvalidOperationException(); 117 | 118 | method(instance, parameter); 119 | } 120 | 121 | protected void Call(ref Delegate storage, string methodName, T parameter) 122 | { 123 | Action method = GetMethodAccessor>(ref storage, methodName); 124 | if (method == null) 125 | throw new InvalidOperationException(); 126 | 127 | method(parameter); 128 | } 129 | 130 | protected abstract object GetInstance(); 131 | 132 | private static Func CreateActivator(Type[] argumentTypes) 133 | { 134 | ConstructorInfo info = typeof(T).GetConstructor(argumentTypes); 135 | if (info == null) 136 | return null; 137 | 138 | Func activator = (arguments) => (T)Activator.CreateInstance(typeof(T), arguments); 139 | 140 | return activator; 141 | } 142 | 143 | private Delegate CreateMethodAccessor(Type type, string name, bool bindInstance = true) 144 | { 145 | if (_type == null) 146 | return null; 147 | 148 | Type[] argumentTypes = LightupServices.GetMethodArgumentTypes(type, bindInstance); 149 | 150 | MethodInfo method = _type.GetMethod(name, argumentTypes); 151 | if (method == null) 152 | return null; 153 | 154 | return LightupServices.CreateDelegate(type, bindInstance ? GetInstance() : null, method); 155 | } 156 | 157 | protected T GetMethodAccessor(ref Delegate storage, string name, bool bindInstance = true) 158 | { 159 | return (T)(object)GetMethodAccessor(ref storage, typeof(T), name, bindInstance); 160 | } 161 | 162 | protected Delegate GetMethodAccessor(ref Delegate storage, Type type, string name, bool bindInstance = true) 163 | { 164 | if (storage == null) 165 | { 166 | Delegate accessor = CreateMethodAccessor(type, name, bindInstance); 167 | 168 | Interlocked.CompareExchange(ref storage, accessor, null); 169 | } 170 | 171 | return storage == LightupServices.NotFound ? null : storage; 172 | } 173 | } 174 | } 175 | 176 | #endif 177 | -------------------------------------------------------------------------------- /Rackspace.Threading/System/LightupServices.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. 3 | 4 | #if !NET40PLUS 5 | 6 | // The reference source is missing documentation 7 | #pragma warning disable SA1600 // Elements must be documented 8 | 9 | namespace System 10 | { 11 | using System.Linq; 12 | using System.Reflection; 13 | 14 | internal static class LightupServices 15 | { 16 | internal static readonly Delegate NotFound = new Action(() => { }); 17 | 18 | public static Delegate ReplaceWith(Delegate d, Type delegateType) 19 | { 20 | return Delegate.CreateDelegate(delegateType, d.Target, d.Method); 21 | } 22 | 23 | public static Type[] GetMethodArgumentTypes(Type actionOrFuncType, bool bindInstance = true) 24 | { 25 | Type[] arguments = actionOrFuncType.GetGenericArguments(); 26 | 27 | if (!bindInstance) 28 | { 29 | // We aren't binding the instance, remove "this" argument 30 | arguments = arguments.Skip(1).ToArray(); 31 | } 32 | 33 | if (IsActionType(actionOrFuncType)) 34 | return arguments; 35 | 36 | // We have a Func, remove it's trailing return type 37 | return arguments.Take(arguments.Length - 1).ToArray(); 38 | } 39 | 40 | public static bool IsActionType(Type type) 41 | { 42 | if (type.IsGenericType) 43 | type = type.GetGenericTypeDefinition(); 44 | 45 | return type == typeof(Action) 46 | || type == typeof(Action<>) 47 | || type == typeof(Action<,>) 48 | || type == typeof(Action<,,>) 49 | || type == typeof(Action<,,,>); 50 | } 51 | 52 | public static Delegate CreateDelegate(Type type, object instance, MethodInfo method) 53 | { 54 | if (method.IsStatic) 55 | instance = null; 56 | 57 | try 58 | { 59 | return Delegate.CreateDelegate(type, instance, method); 60 | } 61 | catch (InvalidOperationException) 62 | { 63 | // Exists, but not callable 64 | } 65 | catch (MemberAccessException) 66 | { 67 | // Exists, but don't have required access 68 | } 69 | 70 | return NotFound; 71 | } 72 | } 73 | } 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /Rackspace.Threading/System/LightupType.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. 3 | 4 | #if !NET40PLUS 5 | 6 | // The reference source is missing documentation 7 | #pragma warning disable SA1600 // Elements must be documented 8 | 9 | namespace System 10 | { 11 | internal static class LightupType 12 | { 13 | public static readonly Type ParameterizedThreadStart = GetExternallyVisibleType("System.Threading.ParameterizedThreadStart, mscorlib"); 14 | public static readonly Type ExecutionContext = GetExternallyVisibleType("System.Threading.ExecutionContext, mscorlib"); 15 | public static readonly Type ContextCallback = GetExternallyVisibleType("System.Threading.ContextCallback, mscorlib"); 16 | public static readonly Type OperatingSystem = GetExternallyVisibleType("System.OperatingSystem, mscorlib"); 17 | 18 | private static Type GetExternallyVisibleType(string typeName) 19 | { 20 | // Types such as ExecutionContext exist on Phone, but are not visible 21 | Type type = Type.GetType(typeName); 22 | if (type != null && type.IsVisible) 23 | return type; 24 | 25 | return null; 26 | } 27 | } 28 | } 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /Rackspace.Threading/System/Runtime/CompilerServices/AsyncMethodTaskCache`1.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. 3 | 4 | #if !NET40PLUS 5 | 6 | namespace System.Runtime.CompilerServices 7 | { 8 | using System.Diagnostics; 9 | using System.Threading.Tasks; 10 | 11 | /// Provides a base class used to cache tasks of a specific return type. 12 | /// Specifies the type of results the cached tasks return. 13 | internal class AsyncMethodTaskCache 14 | { 15 | /// 16 | /// A singleton cache for this result type. This may be if there are no cached tasks for 17 | /// this . 18 | /// 19 | internal static readonly AsyncMethodTaskCache Singleton = CreateCache(); 20 | 21 | /// Creates a non-disposable task. 22 | /// The result for the task. 23 | /// The cacheable task. 24 | internal static TaskCompletionSource CreateCompleted(TResult result) 25 | { 26 | var tcs = new TaskCompletionSource(); 27 | tcs.TrySetResult(result); 28 | return tcs; 29 | } 30 | 31 | /// Creates a cache. 32 | /// A task cache for this result type. 33 | private static AsyncMethodTaskCache CreateCache() 34 | { 35 | // Get the result type 36 | var resultType = typeof(TResult); 37 | 38 | // Return a new cache for this particular kind of task. If we don't have a specialized cache for this type, 39 | // return null. 40 | if (resultType == typeof(bool)) 41 | { 42 | return (AsyncMethodTaskCache)(object)new AsyncMethodBooleanTaskCache(); 43 | } 44 | else if (resultType == typeof(int)) 45 | { 46 | return (AsyncMethodTaskCache)(object)new AsyncMethodInt32TaskCache(); 47 | } 48 | else 49 | { 50 | return null; 51 | } 52 | } 53 | 54 | /// Gets a cached task if one exists. 55 | /// The result for which we want a cached task. 56 | /// A cached task if one exists; otherwise, . 57 | internal virtual TaskCompletionSource FromResult(TResult result) 58 | { 59 | return CreateCompleted(result); 60 | } 61 | 62 | /// Provides a cache for tasks. 63 | private sealed class AsyncMethodBooleanTaskCache : AsyncMethodTaskCache 64 | { 65 | /// A task. 66 | private readonly TaskCompletionSource _true = CreateCompleted(true); 67 | 68 | /// A task. 69 | private readonly TaskCompletionSource _false = CreateCompleted(false); 70 | 71 | /// Gets a cached task for the result. 72 | /// or 73 | /// A cached task for the result. 74 | internal sealed override TaskCompletionSource FromResult(bool result) 75 | { 76 | return result ? _true : _false; 77 | } 78 | } 79 | 80 | /// Provides a cache for tasks. 81 | private sealed class AsyncMethodInt32TaskCache : AsyncMethodTaskCache 82 | { 83 | /// The minimum value, inclusive, for which we want a cached task. 84 | internal const int InclusiveInt32Min = -1; 85 | 86 | /// The maximum value, exclusive, for which we want a cached task. 87 | internal const int ExclusiveInt32Max = 9; 88 | 89 | /// The cache of -returning instances. 90 | internal static readonly TaskCompletionSource[] Int32Tasks = CreateInt32Tasks(); 91 | 92 | /// 93 | /// Creates an array of cached tasks for the values in the range [, 94 | /// ). 95 | /// 96 | /// An array of completion sources for cached integer values. 97 | private static TaskCompletionSource[] CreateInt32Tasks() 98 | { 99 | Debug.Assert(ExclusiveInt32Max >= InclusiveInt32Min, "Expected max to be at least min"); 100 | var tasks = new TaskCompletionSource[ExclusiveInt32Max - InclusiveInt32Min]; 101 | for (int i = 0; i < tasks.Length; i++) 102 | { 103 | tasks[i] = CreateCompleted(i + InclusiveInt32Min); 104 | } 105 | 106 | return tasks; 107 | } 108 | 109 | /// Gets a cached task for the result. 110 | /// The integer value. 111 | /// 112 | /// A cached task for the result; otherwise, if not cached. 113 | /// 114 | internal sealed override TaskCompletionSource FromResult(int result) 115 | { 116 | return (result >= InclusiveInt32Min && result < ExclusiveInt32Max) ? 117 | Int32Tasks[result - InclusiveInt32Min] : 118 | CreateCompleted(result); 119 | } 120 | } 121 | } 122 | } 123 | 124 | #endif 125 | -------------------------------------------------------------------------------- /Rackspace.Threading/System/Runtime/CompilerServices/AsyncServices.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. 3 | 4 | #if NET45PLUS || !NET40PLUS 5 | 6 | // NOTE: If you change this copy, please also change the copy under the Async partition 7 | namespace System.Runtime.CompilerServices 8 | { 9 | using System.Diagnostics.CodeAnalysis; 10 | using System.Threading; 11 | 12 | #if NET45PLUS 13 | using System.Threading.Tasks; 14 | #endif 15 | 16 | #if EXCEPTION_STACK_PRESERVE 17 | using System.Diagnostics; 18 | using System.Reflection; 19 | #endif 20 | 21 | [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:Elements must be documented", Justification = "The reference source is missing documentation")] 22 | internal static class AsyncServices 23 | { 24 | #if EXCEPTION_STACK_PRESERVE 25 | /// 26 | /// A for the internal PrepForRemoting method on . 27 | /// 28 | private static readonly MethodInfo _prepForRemoting = GetPrepForRemotingMethodInfo(); 29 | 30 | /// An empty array to use with . 31 | private static readonly object[] _emptyParams = new object[0]; 32 | #endif 33 | 34 | /// Throws the exception on the thread pool. 35 | /// The exception to propagate. 36 | /// 37 | /// The target context on which to propagate the exception; otherwise, to use the thread 38 | /// pool. 39 | /// 40 | internal static void ThrowAsync(Exception exception, SynchronizationContext targetContext) 41 | { 42 | // If the user supplied a SynchronizationContext... 43 | if (targetContext != null) 44 | { 45 | try 46 | { 47 | // Post the throwing of the exception to that context, and return. 48 | targetContext.Post(state => { throw PrepareExceptionForRethrow((Exception)state); }, exception); 49 | return; 50 | } 51 | catch (Exception postException) 52 | { 53 | // If something goes horribly wrong in the Post, we'll propagate both exceptions on the thread pool 54 | exception = new AggregateException(exception, postException); 55 | } 56 | } 57 | 58 | #if NET45PLUS 59 | Task.Run(() => 60 | { 61 | throw PrepareExceptionForRethrow(exception); 62 | }); 63 | #else 64 | // Propagate the exception(s) on the ThreadPool 65 | ThreadPool.QueueUserWorkItem(state => { throw PrepareExceptionForRethrow((Exception)state); }, exception); 66 | #endif 67 | } 68 | 69 | /// Copies the exception's stack trace so its stack trace isn't overwritten. 70 | /// The exception to prepare. 71 | /// The input exception, . 72 | internal static Exception PrepareExceptionForRethrow(Exception exc) 73 | { 74 | #if EXCEPTION_STACK_PRESERVE 75 | Debug.Assert(exc != null, "Assertion failed: exc != null"); 76 | if (_prepForRemoting != null) 77 | { 78 | try 79 | { 80 | _prepForRemoting.Invoke(exc, _emptyParams); 81 | } 82 | catch 83 | { 84 | } 85 | } 86 | #endif 87 | 88 | return exc; 89 | } 90 | 91 | #if EXCEPTION_STACK_PRESERVE 92 | /// 93 | /// Gets the for the internal PrepForRemoting method on . 94 | /// 95 | /// The if it could be retrieved; otherwise, . 96 | private static MethodInfo GetPrepForRemotingMethodInfo() 97 | { 98 | try 99 | { 100 | return typeof(Exception).GetMethod("PrepForRemoting", BindingFlags.NonPublic | BindingFlags.Instance); 101 | } 102 | catch 103 | { 104 | return null; 105 | } 106 | } 107 | #endif 108 | } 109 | } 110 | 111 | #endif 112 | -------------------------------------------------------------------------------- /Rackspace.Threading/System/Runtime/CompilerServices/AsyncStateMachineAttribute.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. 3 | 4 | #if NET40PLUS 5 | 6 | using System.Runtime.CompilerServices; 7 | 8 | [assembly: TypeForwardedTo(typeof(AsyncStateMachineAttribute))] 9 | 10 | #else 11 | 12 | namespace System.Runtime.CompilerServices 13 | { 14 | /// 15 | /// Indicates whether a method is marked with the modifier. 16 | /// 17 | /// 18 | [Serializable] 19 | [AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)] 20 | public sealed class AsyncStateMachineAttribute : StateMachineAttribute 21 | { 22 | /// 23 | /// Initializes a new instance of the class. 24 | /// 25 | /// 26 | /// The type object for the underlying state machine type that's used to implement a state machine method. 27 | /// 28 | public AsyncStateMachineAttribute(Type stateMachineType) 29 | : base(stateMachineType) 30 | { 31 | } 32 | } 33 | } 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /Rackspace.Threading/System/Runtime/CompilerServices/IAsyncMethodBuilder.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. 3 | 4 | #if !NET40PLUS 5 | 6 | namespace System.Runtime.CompilerServices 7 | { 8 | /// Represents an asynchronous method builder. 9 | internal interface IAsyncMethodBuilder 10 | { 11 | #pragma warning disable SA1600 // Elements must be documented 12 | void PreBoxInitialization(); 13 | #pragma warning restore SA1600 // Elements must be documented 14 | } 15 | } 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /Rackspace.Threading/System/Runtime/CompilerServices/IAsyncStateMachine.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. 3 | 4 | #if NET40PLUS 5 | 6 | using System.Runtime.CompilerServices; 7 | 8 | [assembly: TypeForwardedTo(typeof(IAsyncStateMachine))] 9 | 10 | #else 11 | 12 | namespace System.Runtime.CompilerServices 13 | { 14 | /// 15 | /// Represents state machines generated for asynchronous methods. This type is intended for compiler use only. 16 | /// 17 | /// 18 | public interface IAsyncStateMachine 19 | { 20 | /// Moves the state machine to its next state. 21 | void MoveNext(); 22 | 23 | /// Configures the state machine with a heap-allocated replica. 24 | /// The heap-allocated replica. 25 | void SetStateMachine(IAsyncStateMachine stateMachine); 26 | } 27 | } 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /Rackspace.Threading/System/Runtime/CompilerServices/ICriticalNotifyCompletion.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. 3 | 4 | #if NET40PLUS 5 | 6 | using System.Runtime.CompilerServices; 7 | 8 | [assembly: TypeForwardedTo(typeof(ICriticalNotifyCompletion))] 9 | 10 | #else 11 | 12 | namespace System.Runtime.CompilerServices 13 | { 14 | using System.Security; 15 | using System.Threading; 16 | 17 | /// 18 | /// Represents an awaiter used to schedule continuations when an await operation completes. 19 | /// 20 | /// 21 | public interface ICriticalNotifyCompletion : INotifyCompletion 22 | { 23 | /// Schedules the continuation action to be invoked when the instance completes. 24 | /// The action to invoke when the operation completes. 25 | /// 26 | /// If is . 27 | /// 28 | /// Unlike , need not propagate 29 | /// information. 30 | [SecurityCritical] 31 | void UnsafeOnCompleted(Action continuation); 32 | } 33 | } 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /Rackspace.Threading/System/Runtime/CompilerServices/INotifyCompletion.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. 3 | 4 | #if NET40PLUS 5 | 6 | using System.Runtime.CompilerServices; 7 | 8 | [assembly: TypeForwardedTo(typeof(INotifyCompletion))] 9 | 10 | #else 11 | 12 | namespace System.Runtime.CompilerServices 13 | { 14 | /// 15 | /// Represents an operation that will schedule continuations when the operation completes. 16 | /// 17 | /// 18 | public interface INotifyCompletion 19 | { 20 | /// Schedules the continuation action to be invoked when the instance completes. 21 | /// The action to invoke when the operation completes. 22 | /// 23 | /// If is . 24 | /// 25 | void OnCompleted(Action continuation); 26 | } 27 | } 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /Rackspace.Threading/System/Runtime/CompilerServices/IteratorStateMachineAttribute.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. 3 | 4 | #if NET40PLUS 5 | 6 | using System.Runtime.CompilerServices; 7 | 8 | [assembly: TypeForwardedTo(typeof(IteratorStateMachineAttribute))] 9 | 10 | #else 11 | 12 | namespace System.Runtime.CompilerServices 13 | { 14 | /// 15 | /// Indicates whether a method in Visual Basic is marked with the modifier. 16 | /// 17 | /// 18 | [Serializable] 19 | [AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)] 20 | public sealed class IteratorStateMachineAttribute : StateMachineAttribute 21 | { 22 | /// 23 | /// Initializes a new instance of the class. 24 | /// 25 | /// 26 | /// The type object for the underlying state machine type that's used to implement a state machine method. 27 | /// 28 | public IteratorStateMachineAttribute(Type stateMachineType) 29 | : base(stateMachineType) 30 | { 31 | } 32 | } 33 | } 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /Rackspace.Threading/System/Runtime/CompilerServices/StateMachineAttribute.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. 3 | 4 | #if NET40PLUS 5 | 6 | using System.Runtime.CompilerServices; 7 | 8 | [assembly: TypeForwardedTo(typeof(StateMachineAttribute))] 9 | 10 | #else 11 | 12 | namespace System.Runtime.CompilerServices 13 | { 14 | /// 15 | /// Allows you to determine whether a method is a state machine method. 16 | /// 17 | /// 18 | [Serializable] 19 | [AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)] 20 | public class StateMachineAttribute : Attribute 21 | { 22 | /// 23 | /// This is the backing field for the property. 24 | /// 25 | private readonly Type _stateMachineType; 26 | 27 | /// 28 | /// Initializes a new instance of the class. 29 | /// 30 | /// 31 | /// The type object for the underlying state machine type that was generated by the compiler to implement the 32 | /// state machine method. 33 | /// 34 | public StateMachineAttribute(Type stateMachineType) 35 | { 36 | _stateMachineType = stateMachineType; 37 | } 38 | 39 | /// 40 | /// Gets the type object for the underlying state machine type that was generated by the compiler to implement 41 | /// the state machine method. 42 | /// 43 | /// 44 | /// The type object for the underlying state machine type that was generated by the compiler to implement the 45 | /// state machine method. 46 | /// 47 | public Type StateMachineType 48 | { 49 | get 50 | { 51 | return _stateMachineType; 52 | } 53 | } 54 | } 55 | } 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /Rackspace.Threading/TunnelVisionLabs.Threading.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | TunnelVisionLabs.Threading 5 | 0.0.0 6 | TunnelVisionLabs.Threading 7 | Sam Harwell 8 | Sam Harwell 9 | https://raw.github.com/tunnelvisionlabs/dotnet-threading/v$version$/LICENSE 10 | https://github.com/tunnelvisionlabs/dotnet-threading 11 | true 12 | Utility library to simplify writing asynchronous code which supports .NET 3.5 and newer. 13 | https://github.com/tunnelvisionlabs/dotnet-threading/releases/v$version$ 14 | 15 | threading tasks tpl async await 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /Rackspace.Threading/VoidResult.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. 3 | 4 | namespace Rackspace.Threading 5 | { 6 | using System.Threading.Tasks; 7 | 8 | /// 9 | /// This type is used as the task type for instances of intended to 10 | /// represent a which is not a . Since this type is not externally 11 | /// visible, users will not be able to cast the task to a . 12 | /// 13 | /// 14 | internal struct VoidResult 15 | { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Rackspace.Threading/packages.Rackspace.Threading.net35-client.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Rackspace.Threading/packages.Rackspace.Threading.net40-client.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Rackspace.Threading/packages.Rackspace.Threading.net45.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Rackspace.Threading/packages.Rackspace.Threading.netcore45.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Rackspace.Threading/packages.Rackspace.Threading.portable-net40.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Rackspace.Threading/packages.Rackspace.Threading.portable-net45.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Samples/CSharpSamples/CSharpSamples.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | {9F8D12B2-273B-4C1A-9CDB-79120E4B66B6} 7 | Library 8 | Properties 9 | CSharpSamples 10 | CSharpSamples 11 | v4.5 12 | 512 13 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 14 | 10.0 15 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 16 | $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages 17 | False 18 | UnitTest 19 | 20 | 21 | 22 | true 23 | full 24 | false 25 | bin\Debug\ 26 | DEBUG;TRACE 27 | prompt 28 | 4 29 | false 30 | bin\Debug\CSharpSamples.xml 31 | 1591 32 | 33 | 34 | pdbonly 35 | true 36 | bin\Release\ 37 | TRACE 38 | prompt 39 | 4 40 | false 41 | bin\Release\CSharpSamples.xml 42 | 1591 43 | 44 | 45 | 46 | 47 | 3.5 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | {808f5d89-ff4f-43d5-8ba7-e558ad4945d7} 72 | Rackspace.Threading.net45 73 | 74 | 75 | 76 | 77 | 78 | 79 | False 80 | 81 | 82 | False 83 | 84 | 85 | False 86 | 87 | 88 | False 89 | 90 | 91 | 92 | 93 | 94 | 95 | 102 | -------------------------------------------------------------------------------- /Samples/CSharpSamples/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Rackspace, US Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. 2 | 3 | using System; 4 | using System.Reflection; 5 | using System.Runtime.InteropServices; 6 | 7 | // General Information about an assembly is controlled through the following 8 | // set of attributes. Change these attribute values to modify the information 9 | // associated with an assembly. 10 | [assembly: AssemblyTitle("CSharpSamples")] 11 | [assembly: AssemblyDescription("")] 12 | [assembly: AssemblyConfiguration("")] 13 | [assembly: AssemblyCompany("Tunnel Vision Laboratories, LLC")] 14 | [assembly: AssemblyProduct("CSharpSamples")] 15 | [assembly: AssemblyCopyright("Copyright © Sam Harwell 2015")] 16 | [assembly: AssemblyTrademark("")] 17 | [assembly: AssemblyCulture("")] 18 | [assembly: CLSCompliant(true)] 19 | 20 | #if !PORTABLE 21 | // Setting ComVisible to false makes the types in this assembly not visible 22 | // to COM components. If you need to access a type in this assembly from 23 | // COM, set the ComVisible attribute to true on that type. 24 | [assembly: ComVisible(false)] 25 | #endif 26 | 27 | [assembly: AssemblyVersion("1.0.0.0")] 28 | [assembly: AssemblyFileVersion("1.0.0.0")] 29 | [assembly: AssemblyInformationalVersion("1.0.0.0-dev")] 30 | -------------------------------------------------------------------------------- /Samples/CSharpSamples/TaskBlockUsing.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Rackspace, US Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. 2 | 3 | namespace CSharpSamples 4 | { 5 | using System; 6 | using System.Threading.Tasks; 7 | using Microsoft.VisualStudio.TestTools.UnitTesting; 8 | using Rackspace.Threading; 9 | using StringBuilder = System.Text.StringBuilder; 10 | using StringWriter = System.IO.StringWriter; 11 | 12 | /// 13 | /// This class contains unit-tested example code for the 14 | /// building block method. 15 | /// 16 | [TestClass] 17 | public class TaskBlockUsing 18 | { 19 | private const string SampleText = "Text to read"; 20 | 21 | [TestMethod] 22 | public async Task TestUsingAsyncAwait() 23 | { 24 | StringBuilder builder = new StringBuilder(); 25 | await UsingAsyncAwait(builder); 26 | Assert.AreEqual(SampleText, builder.ToString()); 27 | } 28 | 29 | [TestMethod] 30 | public async Task TestUsingAsyncBuildingBlock() 31 | { 32 | StringBuilder builder = new StringBuilder(); 33 | await Using(builder); 34 | Assert.AreEqual(SampleText, builder.ToString()); 35 | } 36 | 37 | #pragma warning disable 1998 // This async method lacks 'await' operators and will run synchronously.... 38 | #region UsingAsyncAwait 39 | public async Task UsingAsyncAwait(StringBuilder builder) 40 | { 41 | using (StringWriter resource = await AcquireResourceAsyncAwait(builder)) 42 | { 43 | await resource.WriteAsync(SampleText); 44 | } 45 | } 46 | 47 | private async Task AcquireResourceAsyncAwait(StringBuilder builder) 48 | { 49 | // this would generally contain an asynchronous call 50 | return new StringWriter(builder); 51 | } 52 | #endregion 53 | #pragma warning restore 1998 54 | 55 | #region UsingAsyncBuildingBlock 56 | public Task Using(StringBuilder builder) 57 | { 58 | return TaskBlocks.Using( 59 | () => AcquireResourceAsync(builder), 60 | task => task.Result.WriteAsync(SampleText)); 61 | } 62 | 63 | private Task AcquireResourceAsync(StringBuilder builder) 64 | { 65 | // this would generally contain an asynchronous call 66 | return CompletedTask.FromResult(new StringWriter(builder)); 67 | } 68 | #endregion 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Samples/CSharpSamples/TaskBlockUsingWithResult.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Rackspace, US Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. 2 | 3 | namespace CSharpSamples 4 | { 5 | using System; 6 | using System.Threading.Tasks; 7 | using Microsoft.VisualStudio.TestTools.UnitTesting; 8 | using Rackspace.Threading; 9 | using StringReader = System.IO.StringReader; 10 | 11 | /// 12 | /// This class contains unit-tested example code for the 13 | /// building block method. 14 | /// 15 | [TestClass] 16 | public class TaskBlockUsingWithResult 17 | { 18 | private const string SampleText = "Text to read"; 19 | 20 | [TestMethod] 21 | public async Task TestUsingWithResultAsyncAwait() 22 | { 23 | string text = await UsingWithResultAsyncAwait(); 24 | Assert.AreEqual(SampleText, text); 25 | } 26 | 27 | [TestMethod] 28 | public async Task TestUsingWithResultAsyncBuildingBlock() 29 | { 30 | string text = await UsingWithResult(); 31 | Assert.AreEqual(SampleText, text); 32 | } 33 | 34 | #pragma warning disable 1998 // This async method lacks 'await' operators and will run synchronously.... 35 | #region UsingWithResultAsyncAwait 36 | public async Task UsingWithResultAsyncAwait() 37 | { 38 | using (StringReader resource = await AcquireResourceAsyncAwait()) 39 | { 40 | return await resource.ReadToEndAsync(); 41 | } 42 | } 43 | 44 | private async Task AcquireResourceAsyncAwait() 45 | { 46 | // this would generally contain an asynchronous call 47 | return new StringReader("Text to read"); 48 | } 49 | #endregion 50 | #pragma warning restore 1998 51 | 52 | #region UsingWithResultAsyncBuildingBlock 53 | public Task UsingWithResult() 54 | { 55 | return TaskBlocks.Using( 56 | () => AcquireResourceAsync(), 57 | task => task.Result.ReadToEndAsync()); 58 | } 59 | 60 | private Task AcquireResourceAsync() 61 | { 62 | // this would generally contain an asynchronous call 63 | return CompletedTask.FromResult(new StringReader("Text to read")); 64 | } 65 | #endregion 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Samples/CSharpSamples/TaskBlockWhileAsync.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Rackspace, US Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. 2 | 3 | namespace CSharpSamples 4 | { 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Threading.Tasks; 8 | using Microsoft.VisualStudio.TestTools.UnitTesting; 9 | using Rackspace.Threading; 10 | 11 | /// 12 | /// This class contains unit-tested example code for the 13 | /// building block method. 14 | /// 15 | [TestClass] 16 | public class TaskBlockWhileAsync 17 | { 18 | [TestMethod] 19 | public async Task TestWhileAsyncAwait() 20 | { 21 | await WhileAsyncAwait(); 22 | } 23 | 24 | [TestMethod] 25 | public async Task TestWhile() 26 | { 27 | await While(); 28 | } 29 | 30 | #pragma warning disable 1998 // This async method lacks 'await' operators and will run synchronously.... 31 | #region WhileAsyncAwait 32 | public async Task WhileAsyncAwait() 33 | { 34 | Stack workList = new Stack(new[] { 3, 5, 7 }); 35 | while (workList.Count > 0) 36 | { 37 | await ProcessWorkItemAsyncAwait(workList.Pop()); 38 | } 39 | } 40 | 41 | private async Task ProcessWorkItemAsyncAwait(int item) 42 | { 43 | // this would typically perform an asynchronous operation on the 44 | // work item 45 | } 46 | #endregion 47 | #pragma warning restore 1998 48 | 49 | #region WhileAsyncBuildingBlock 50 | public Task While() 51 | { 52 | Stack workList = new Stack(new[] { 3, 5, 7 }); 53 | return TaskBlocks.While( 54 | () => workList.Count > 0, 55 | () => ProcessWorkItemAsync(workList.Pop())); 56 | } 57 | 58 | private Task ProcessWorkItemAsync(int item) 59 | { 60 | // this would typically perform an asynchronous operation on the 61 | // work item 62 | return CompletedTask.Default; 63 | } 64 | #endregion 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Samples/CSharpSamples/TaskBlockWhileAsyncCondition.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Rackspace, US Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. 2 | 3 | namespace CSharpSamples 4 | { 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Threading.Tasks; 8 | using Microsoft.VisualStudio.TestTools.UnitTesting; 9 | using Rackspace.Threading; 10 | 11 | /// 12 | /// This class contains unit-tested example code for the 13 | /// building block method. 14 | /// 15 | [TestClass] 16 | public class TaskBlockWhileAsyncCondition 17 | { 18 | [TestMethod] 19 | public async Task TestWhileAsyncAwait() 20 | { 21 | await WhileAsyncAwait(); 22 | } 23 | 24 | [TestMethod] 25 | public async Task TestWhile() 26 | { 27 | await While(); 28 | } 29 | 30 | #pragma warning disable 1998 // This async method lacks 'await' operators and will run synchronously.... 31 | #region WhileAsyncAwait 32 | public async Task WhileAsyncAwait() 33 | { 34 | Stack workList = new Stack(new[] { 3, 5, 7 }); 35 | while (await HasItemsAsyncAwait(workList)) 36 | { 37 | await ProcessWorkItemAsyncAwait(workList.Pop()); 38 | } 39 | } 40 | 41 | private async Task HasItemsAsyncAwait(Stack workList) 42 | { 43 | // this would typically perform an asynchronous operation to test 44 | // some condition of the input parameter(s) 45 | return workList.Count > 0; 46 | } 47 | 48 | private async Task ProcessWorkItemAsyncAwait(int item) 49 | { 50 | // this would typically perform an asynchronous operation on the 51 | // work item 52 | } 53 | #endregion 54 | #pragma warning restore 1998 55 | 56 | #region WhileAsyncBuildingBlock 57 | public Task While() 58 | { 59 | Stack workList = new Stack(new[] { 3, 5, 7 }); 60 | return TaskBlocks.While( 61 | () => HasItemsAsync(workList), 62 | () => ProcessWorkItemAsync(workList.Pop())); 63 | } 64 | 65 | private Task HasItemsAsync(Stack workList) 66 | { 67 | // this would typically perform an asynchronous operation to test 68 | // some condition of the input parameter(s) 69 | return CompletedTask.FromResult(workList.Count > 0); 70 | } 71 | 72 | private Task ProcessWorkItemAsync(int item) 73 | { 74 | // this would typically perform an asynchronous operation on the 75 | // work item 76 | return CompletedTask.Default; 77 | } 78 | #endregion 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /Tests/UnitTest.RackspaceThreading/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. 3 | 4 | using System; 5 | using System.Reflection; 6 | using System.Runtime.InteropServices; 7 | 8 | // General Information about an assembly is controlled through the following 9 | // set of attributes. Change these attribute values to modify the information 10 | // associated with an assembly. 11 | [assembly: AssemblyTitle("UnitTest.RackspaceThreading")] 12 | [assembly: AssemblyDescription("")] 13 | [assembly: AssemblyConfiguration("")] 14 | [assembly: AssemblyCompany("Tunnel Vision Laboratories, LLC")] 15 | [assembly: AssemblyProduct("UnitTest.TunnelVisionLabsThreading")] 16 | [assembly: AssemblyCopyright("Copyright © Sam Harwell 2015")] 17 | [assembly: AssemblyTrademark("")] 18 | [assembly: AssemblyCulture("")] 19 | [assembly: CLSCompliant(true)] 20 | 21 | #if !PORTABLE 22 | // Setting ComVisible to false makes the types in this assembly not visible 23 | // to COM components. If you need to access a type in this assembly from 24 | // COM, set the ComVisible attribute to true on that type. 25 | [assembly: ComVisible(false)] 26 | #endif 27 | 28 | [assembly: AssemblyVersion("1.0.0.0")] 29 | [assembly: AssemblyFileVersion("1.0.0.0")] 30 | [assembly: AssemblyInformationalVersion("1.0.0.0-dev")] 31 | -------------------------------------------------------------------------------- /Tests/UnitTest.RackspaceThreading/TaskTestingBase.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. 3 | 4 | #pragma warning disable SA1609 // Property documentation must have value 5 | #pragma warning disable SA1623 // Property summary documentation must match accessors 6 | 7 | namespace UnitTest.RackspaceThreading 8 | { 9 | using System; 10 | using System.Threading.Tasks; 11 | using Microsoft.VisualStudio.TestTools.UnitTesting; 12 | 13 | [TestClass] 14 | public abstract class TaskTestingBase 15 | { 16 | private bool _unobservedException; 17 | 18 | /// 19 | /// During testing, timed events are assumed to be ordered if their expected times differ by more than 20 | /// . Reducing this value increases confidence that events occur at the requested 21 | /// time, but may increase the number of false test failures. 22 | /// 23 | /// 24 | /// This value is greater than . 25 | /// 26 | public TimeSpan TimingGranularity 27 | { 28 | get 29 | { 30 | string granularity = Environment.GetEnvironmentVariable("TIMING_GRANULARITY_MS"); 31 | int result; 32 | if (!int.TryParse(granularity, out result)) 33 | return TimeSpan.FromMilliseconds(10); 34 | 35 | return TimeSpan.FromMilliseconds(result); 36 | } 37 | } 38 | 39 | /// 40 | /// During testing, timed events should occur no more than in advance of the 41 | /// requested time. Reducing this value increases confidence that events occur at the requested time, but may 42 | /// increase the number of false test failures. 43 | /// 44 | /// 45 | /// This value is greater than or equal to . 46 | /// 47 | public TimeSpan AdvanceTolerance 48 | { 49 | get 50 | { 51 | string tolerance = Environment.GetEnvironmentVariable("ADVANCE_TOLERANCE_MS"); 52 | int result; 53 | if (!int.TryParse(tolerance, out result)) 54 | return TimeSpan.FromMilliseconds(25); 55 | 56 | return TimeSpan.FromMilliseconds(result); 57 | } 58 | } 59 | 60 | /// 61 | /// During testing, timed events should occur no more than following the requested 62 | /// time. Reducing this value increases confidence that events occur at the requested time, but may increase the 63 | /// number of false test failures. 64 | /// 65 | /// 66 | /// This value is greater than or equal to . 67 | /// 68 | public TimeSpan DelayTolerance 69 | { 70 | get 71 | { 72 | string tolerance = Environment.GetEnvironmentVariable("DELAY_TOLERANCE_MS"); 73 | int result; 74 | if (!int.TryParse(tolerance, out result)) 75 | return TimeSpan.FromMilliseconds(25); 76 | 77 | return TimeSpan.FromMilliseconds(result); 78 | } 79 | } 80 | 81 | [TestInitialize] 82 | public void TestInitialize() 83 | { 84 | _unobservedException = false; 85 | TaskScheduler.UnobservedTaskException += HandleUnobservedException; 86 | } 87 | 88 | private void HandleUnobservedException(object sender, UnobservedTaskExceptionEventArgs e) 89 | { 90 | _unobservedException = true; 91 | e.SetObserved(); 92 | } 93 | 94 | /// 95 | /// This method ensures failures in the finalizers do not impact other tests. 96 | /// 97 | [TestCleanup] 98 | public void TestCleanup() 99 | { 100 | GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); 101 | GC.WaitForPendingFinalizers(); 102 | TaskScheduler.UnobservedTaskException -= HandleUnobservedException; 103 | Assert.IsFalse(_unobservedException, "Failed to observe a task exception."); 104 | } 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /Tests/UnitTest.RackspaceThreading/TestAsyncAwait.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. 3 | 4 | namespace UnitTest.RackspaceThreading 5 | { 6 | using System; 7 | using System.Threading.Tasks; 8 | using Microsoft.VisualStudio.TestTools.UnitTesting; 9 | using Rackspace.Threading; 10 | #if NET45PLUS 11 | using NullExceptionType = System.NullReferenceException; 12 | #else 13 | using NullExceptionType = System.ArgumentNullException; 14 | #endif 15 | 16 | [TestClass] 17 | public class TestAsyncAwait : TaskTestingBase 18 | { 19 | [TestMethod] 20 | [TestCategory("Async")] 21 | public void TestUnwrapException() 22 | { 23 | TestUnwrapExceptionAsync().Wait(); 24 | } 25 | 26 | private async Task TestUnwrapExceptionAsync() 27 | { 28 | try 29 | { 30 | await CompletedTask.Default.Select( 31 | _ => 32 | { 33 | throw new ArgumentNullException(); 34 | }); 35 | Assert.Fail("Expected an exception"); 36 | } 37 | catch (ArgumentNullException) 38 | { 39 | } 40 | } 41 | 42 | [TestMethod] 43 | [TestCategory("Async")] 44 | public void TestAwaitNullTask() 45 | { 46 | TestAwaitNullTaskAsync().Wait(); 47 | } 48 | 49 | private async Task TestAwaitNullTaskAsync() 50 | { 51 | try 52 | { 53 | #pragma warning disable CS1720 // Expression will always cause a System.NullReferenceException because the type's default value is null 54 | await default(Task); 55 | #pragma warning restore CS1720 // Expression will always cause a System.NullReferenceException because the type's default value is null 56 | Assert.Fail("Expected an exception"); 57 | } 58 | catch (NullExceptionType) 59 | { 60 | } 61 | } 62 | 63 | [TestMethod] 64 | [TestCategory("Async")] 65 | public void TestAwaitNullTaskT() 66 | { 67 | TestAwaitNullTaskTAsync().Wait(); 68 | } 69 | 70 | private async Task TestAwaitNullTaskTAsync() 71 | { 72 | try 73 | { 74 | #pragma warning disable CS1720 // Expression will always cause a System.NullReferenceException because the type's default value is null 75 | await default(Task); 76 | #pragma warning restore CS1720 // Expression will always cause a System.NullReferenceException because the type's default value is null 77 | Assert.Fail("Expected an exception"); 78 | } 79 | catch (NullExceptionType) 80 | { 81 | } 82 | } 83 | 84 | [TestMethod] 85 | [TestCategory("Async")] 86 | [ExpectedException(typeof(NullExceptionType))] 87 | public void TestConfigureAwaitNullTask() 88 | { 89 | #pragma warning disable CS1720 // Expression will always cause a System.NullReferenceException because the type's default value is null 90 | default(Task).ConfigureAwait(true); 91 | #pragma warning restore CS1720 // Expression will always cause a System.NullReferenceException because the type's default value is null 92 | } 93 | 94 | [TestMethod] 95 | [TestCategory("Async")] 96 | [ExpectedException(typeof(NullExceptionType))] 97 | public void TestConfigureAwaitNullTaskT() 98 | { 99 | #pragma warning disable CS1720 // Expression will always cause a System.NullReferenceException because the type's default value is null 100 | default(Task).ConfigureAwait(true); 101 | #pragma warning restore CS1720 // Expression will always cause a System.NullReferenceException because the type's default value is null 102 | } 103 | 104 | [TestMethod] 105 | [TestCategory("Async")] 106 | public void TestConfigureAwaitTrue() 107 | { 108 | TestConfigureAwaitAsync(true).Wait(); 109 | } 110 | 111 | [TestMethod] 112 | [TestCategory("Async")] 113 | public void TestConfigureAwaitFalse() 114 | { 115 | TestConfigureAwaitAsync(false).Wait(); 116 | } 117 | 118 | private async Task TestConfigureAwaitAsync(bool continueOnCapturedContext) 119 | { 120 | await DelayedTask.Delay(TimingGranularity).ConfigureAwait(continueOnCapturedContext); 121 | } 122 | 123 | [TestMethod] 124 | [TestCategory("Async")] 125 | public void TestConfigureAwaitTrueTaskT() 126 | { 127 | TestConfigureAwaitTaskTAsync(true).Wait(); 128 | } 129 | 130 | [TestMethod] 131 | [TestCategory("Async")] 132 | public void TestConfigureAwaitFalseTaskT() 133 | { 134 | TestConfigureAwaitTaskTAsync(false).Wait(); 135 | } 136 | 137 | private async Task TestConfigureAwaitTaskTAsync(bool continueOnCapturedContext) 138 | { 139 | await DelayedTask.Delay(TimingGranularity).Select(_ => 0).ConfigureAwait(continueOnCapturedContext); 140 | } 141 | 142 | [TestMethod] 143 | [TestCategory("Async")] 144 | public void TestYield() 145 | { 146 | TestYieldAsync().Wait(); 147 | } 148 | 149 | private async Task TestYieldAsync() 150 | { 151 | await DelayedTask.Yield(); 152 | } 153 | 154 | [TestMethod] 155 | [TestCategory("Async")] 156 | public void TestReturnTrue() 157 | { 158 | Assert.IsTrue(TestReturnBooleanAsync(true).Result); 159 | } 160 | 161 | [TestMethod] 162 | [TestCategory("Async")] 163 | public void TestReturnFalse() 164 | { 165 | Assert.IsFalse(TestReturnBooleanAsync(false).Result); 166 | } 167 | 168 | #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously 169 | private async Task TestReturnBooleanAsync(bool value) 170 | #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously 171 | { 172 | return value; 173 | } 174 | 175 | [TestMethod] 176 | [TestCategory("Async")] 177 | public void TestReturnZero() 178 | { 179 | Assert.AreEqual(0, TestReturnZeroAsync().Result); 180 | } 181 | 182 | #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously 183 | private async Task TestReturnZeroAsync() 184 | #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously 185 | { 186 | return 0; 187 | } 188 | 189 | [TestMethod] 190 | [TestCategory("Async")] 191 | public void TestReturnZeroAfterDelay() 192 | { 193 | Assert.AreEqual(0, TestReturnZeroAfterDelayAsync().Result); 194 | } 195 | 196 | private async Task TestReturnZeroAfterDelayAsync() 197 | { 198 | await DelayedTask.Delay(TimingGranularity); 199 | return 0; 200 | } 201 | } 202 | } 203 | -------------------------------------------------------------------------------- /Tests/UnitTest.RackspaceThreading/TestCompletedTask.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. 3 | 4 | namespace UnitTest.RackspaceThreading 5 | { 6 | using System; 7 | using System.Diagnostics; 8 | using System.Threading.Tasks; 9 | using Microsoft.VisualStudio.TestTools.UnitTesting; 10 | using Rackspace.Threading; 11 | 12 | [TestClass] 13 | public class TestCompletedTask : TaskTestingBase 14 | { 15 | [TestMethod] 16 | public void TestCancelled() 17 | { 18 | Task cancelledTask = CompletedTask.Canceled(); 19 | Assert.AreEqual(TaskStatus.Canceled, cancelledTask.Status); 20 | Assert.IsTrue(cancelledTask.IsCanceled); 21 | 22 | try 23 | { 24 | cancelledTask.Wait(); 25 | Assert.Fail("Expected a TaskCanceledException wrapped in an AggregateException"); 26 | } 27 | catch (AggregateException ex) 28 | { 29 | Assert.AreEqual(1, ex.InnerExceptions.Count); 30 | Assert.IsInstanceOfType(ex.InnerExceptions[0], typeof(TaskCanceledException)); 31 | } 32 | } 33 | 34 | [TestMethod] 35 | public void TestCancelledGetsDisposed() 36 | { 37 | CompletedTask.Canceled().Dispose(); 38 | TestCancelled(); 39 | 40 | Assert.IsTrue(CompletedTask.Canceled().Select(_ => default(object)).IsCanceled); 41 | Assert.IsTrue(CoreTaskExtensions.Then(CompletedTask.Canceled(), _ => CompletedTask.Default).IsCanceled); 42 | } 43 | 44 | [TestMethod] 45 | public void TestCancelledT() 46 | { 47 | Task cancelledTask = CompletedTask.Canceled(); 48 | Assert.AreEqual(TaskStatus.Canceled, cancelledTask.Status); 49 | Assert.IsTrue(cancelledTask.IsCanceled); 50 | 51 | try 52 | { 53 | cancelledTask.Wait(); 54 | Assert.Fail("Expected a TaskCanceledException wrapped in an AggregateException"); 55 | } 56 | catch (AggregateException ex) 57 | { 58 | Assert.AreEqual(1, ex.InnerExceptions.Count); 59 | Assert.IsInstanceOfType(ex.InnerExceptions[0], typeof(TaskCanceledException)); 60 | } 61 | 62 | try 63 | { 64 | int result = cancelledTask.Result; 65 | Assert.Fail("Expected a TaskCanceledException wrapped in an AggregateException"); 66 | } 67 | catch (AggregateException ex) 68 | { 69 | Assert.AreEqual(1, ex.InnerExceptions.Count); 70 | Assert.IsInstanceOfType(ex.InnerExceptions[0], typeof(TaskCanceledException)); 71 | } 72 | } 73 | 74 | [TestMethod] 75 | public void TestCancelledTGetsDisposed() 76 | { 77 | CompletedTask.Canceled().Dispose(); 78 | TestCancelledT(); 79 | 80 | Assert.IsTrue(CompletedTask.Canceled().Select(_ => default(object)).IsCanceled); 81 | Assert.IsTrue(CoreTaskExtensions.Then(CompletedTask.Canceled(), _ => CompletedTask.Default).IsCanceled); 82 | } 83 | 84 | [TestMethod] 85 | public void TestDefault() 86 | { 87 | Task completedTask = CompletedTask.Default; 88 | Assert.AreEqual(TaskStatus.RanToCompletion, completedTask.Status); 89 | Assert.IsTrue(completedTask.IsCompleted); 90 | 91 | Stopwatch timer = Stopwatch.StartNew(); 92 | Task.WaitAll(new[] { completedTask }); 93 | Assert.IsTrue(timer.Elapsed <= TimeSpan.FromMilliseconds(5), "Waiting on CompletedTask.Default resulted in an unexpected delay ({0}ms > 5ms)", timer.Elapsed.TotalMilliseconds); 94 | } 95 | 96 | [TestMethod] 97 | public void TestDefaultGetsDisposed() 98 | { 99 | CompletedTask.Default.Dispose(); 100 | TestDefault(); 101 | 102 | Assert.IsTrue(CompletedTask.Default.Select(_ => default(object)).IsCompleted); 103 | Assert.IsTrue(CoreTaskExtensions.Then(CompletedTask.Default, _ => CompletedTask.Default).IsCompleted); 104 | } 105 | 106 | [TestMethod] 107 | public void TestDefaultT() 108 | { 109 | int expected = 3; 110 | 111 | Task completedTask = CompletedTask.FromResult(expected); 112 | Assert.AreEqual(TaskStatus.RanToCompletion, completedTask.Status); 113 | Assert.IsTrue(completedTask.IsCompleted); 114 | Assert.AreEqual(expected, completedTask.Result); 115 | 116 | Stopwatch timer = Stopwatch.StartNew(); 117 | Task.WaitAll(new[] { completedTask }); 118 | Assert.IsTrue(timer.Elapsed <= TimeSpan.FromMilliseconds(5), "Waiting on CompletedTask.Default resulted in an unexpected delay ({0}ms > 5ms)", timer.Elapsed.TotalMilliseconds); 119 | } 120 | 121 | [TestMethod] 122 | public void TestDefaultTObject() 123 | { 124 | object expected = new object(); 125 | 126 | Task completedTask = CompletedTask.FromResult(expected); 127 | Assert.AreEqual(TaskStatus.RanToCompletion, completedTask.Status); 128 | Assert.IsTrue(completedTask.IsCompleted); 129 | Assert.AreSame(expected, completedTask.Result); 130 | 131 | Stopwatch timer = Stopwatch.StartNew(); 132 | Task.WaitAll(new[] { completedTask }); 133 | Assert.IsTrue(timer.Elapsed <= TimeSpan.FromMilliseconds(5), "Waiting on CompletedTask.Default resulted in an unexpected delay ({0}ms > 5ms)", timer.Elapsed.TotalMilliseconds); 134 | } 135 | 136 | /// 137 | /// This test verifies that allows 138 | /// arguments. 139 | /// 140 | [TestMethod] 141 | public void TestDefaultTObject_Null() 142 | { 143 | Task completedTask = CompletedTask.FromResult(default(object)); 144 | Assert.AreEqual(TaskStatus.RanToCompletion, completedTask.Status); 145 | Assert.IsTrue(completedTask.IsCompleted); 146 | Assert.IsNull(completedTask.Result); 147 | 148 | Stopwatch timer = Stopwatch.StartNew(); 149 | Task.WaitAll(new[] { completedTask }); 150 | Assert.IsTrue(timer.Elapsed <= TimeSpan.FromMilliseconds(5), "Waiting on CompletedTask.Default resulted in an unexpected delay ({0}ms > 5ms)", timer.Elapsed.TotalMilliseconds); 151 | } 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /Tests/UnitTest.RackspaceThreading/TestProgress.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. 2 | // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. 3 | 4 | namespace UnitTest.RackspaceThreading 5 | { 6 | using System; 7 | using System.Threading; 8 | using System.Threading.Tasks; 9 | using Microsoft.VisualStudio.TestTools.UnitTesting; 10 | using Rackspace.Threading; 11 | 12 | [TestClass] 13 | public class TestProgress : TaskTestingBase 14 | { 15 | [TestMethod] 16 | [Timeout(2000)] 17 | public void TestCreateProgressT_Event() 18 | { 19 | int progressValue = 0; 20 | ManualResetEvent mre = new ManualResetEvent(false); 21 | 22 | var progressObject = new Rackspace.Threading.Progress(); 23 | progressObject.ProgressChanged += 24 | (sender, e) => 25 | { 26 | progressValue = e.Progress; 27 | mre.Set(); 28 | }; 29 | 30 | IProgress progress = progressObject; 31 | progress.Report(3); 32 | mre.WaitOne(); 33 | 34 | Assert.AreEqual(3, progressValue); 35 | } 36 | 37 | [TestMethod] 38 | [Timeout(2000)] 39 | public void TestCreateProgressT_Handler() 40 | { 41 | int progressValue = 0; 42 | ManualResetEvent mre = new ManualResetEvent(false); 43 | 44 | var progressObject = new Rackspace.Threading.Progress( 45 | value => 46 | { 47 | progressValue = value; 48 | mre.Set(); 49 | }); 50 | 51 | IProgress progress = progressObject; 52 | progress.Report(3); 53 | mre.WaitOne(); 54 | 55 | Assert.AreEqual(3, progressValue); 56 | } 57 | 58 | [TestMethod] 59 | [Timeout(2000)] 60 | public void TestCreateProgressT_HandlerAndEvent() 61 | { 62 | int handlerProgressValue = 0; 63 | int eventProgressValue = 0; 64 | ManualResetEvent handlerMre = new ManualResetEvent(false); 65 | ManualResetEvent eventMre = new ManualResetEvent(false); 66 | 67 | var progressObject = new Rackspace.Threading.Progress( 68 | value => 69 | { 70 | handlerProgressValue = value; 71 | handlerMre.Set(); 72 | }); 73 | progressObject.ProgressChanged += 74 | (sender, e) => 75 | { 76 | eventProgressValue = e.Progress; 77 | eventMre.Set(); 78 | }; 79 | 80 | IProgress progress = progressObject; 81 | progress.Report(3); 82 | handlerMre.WaitOne(); 83 | eventMre.WaitOne(); 84 | 85 | Assert.AreEqual(3, handlerProgressValue); 86 | Assert.AreEqual(3, eventProgressValue); 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /Tests/UnitTest.RackspaceThreading/UnitTest.RackspaceThreading.net45.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | {33E4C444-B346-48BB-90C9-DA7E983C8BE5} 7 | Library 8 | Properties 9 | UnitTest.RackspaceThreading 10 | UnitTest.RackspaceThreading.net45 11 | v4.5 12 | 512 13 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 14 | 10.0 15 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 16 | $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages 17 | False 18 | UnitTest 19 | obj\net45\ 20 | ..\..\ 21 | 22 | 23 | true 24 | full 25 | false 26 | bin\net45\Debug\ 27 | DEBUG;TRACE;NET45;NET45PLUS;NET40PLUS;NET35PLUS 28 | prompt 29 | 4 30 | bin\net45\Debug\UnitTest.RackspaceThreading.net45.xml 31 | 1591 32 | ..\..\TunnelVisionLabs.Threading.UnitTest.ruleset 33 | 34 | 35 | pdbonly 36 | true 37 | bin\net45\Release\ 38 | TRACE;NET45;NET45PLUS;NET40PLUS;NET35PLUS 39 | prompt 40 | 4 41 | bin\net45\Release\UnitTest.RackspaceThreading.net45.xml 42 | 1591 43 | ..\..\TunnelVisionLabs.Threading.UnitTest.ruleset 44 | 45 | 46 | 47 | False 48 | ..\..\packages\Newtonsoft.Json.6.0.3\lib\net45\Newtonsoft.Json.dll 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | {808f5d89-ff4f-43d5-8ba7-e558ad4945d7} 86 | Rackspace.Threading.net45 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | stylecop.json 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | False 107 | 108 | 109 | False 110 | 111 | 112 | False 113 | 114 | 115 | False 116 | 117 | 118 | 119 | 120 | 121 | 122 | 129 | -------------------------------------------------------------------------------- /Tests/UnitTest.RackspaceThreading/packages.UnitTest.RackspaceThreading.net35-client.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Tests/UnitTest.RackspaceThreading/packages.UnitTest.RackspaceThreading.net40-client.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Tests/UnitTest.RackspaceThreading/packages.UnitTest.RackspaceThreading.net45.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Tests/UnitTest.RackspaceThreading/packages.UnitTest.RackspaceThreading.portable-net40.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Tests/UnitTest.RackspaceThreading/packages.UnitTest.RackspaceThreading.portable-net45.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /TunnelVisionLabs.Threading.UnitTest.ruleset: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /TunnelVisionLabs.Threading.ruleset: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: 1.0.{build} 2 | os: Visual Studio 2015 3 | configuration: Release 4 | environment: 5 | DELAY_TOLERANCE_MS: 50 6 | TIMING_GRANULARITY_MS: 30 7 | init: 8 | - git config --global core.autocrlf true 9 | build_script: 10 | - cd build 11 | - powershell -Command .\build.ps1 -VisualStudioVersion "14.0" -InstallSHFB -Verbosity minimal -Logger "${env:ProgramFiles}\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" 12 | - cd .. 13 | after_build: 14 | - cd build 15 | - powershell -Command .\appveyor-deploy-docs.ps1 16 | - cd .. 17 | test_script: 18 | - vstest.console /logger:Appveyor /TestCaseFilter:"(TestCategory!=WebRequest)&(TestCategory!=Async)" "C:\projects\dotnet-threading\Tests\UnitTest.RackspaceThreading\bin\net45\%CONFIGURATION%\UnitTest.RackspaceThreading.net45.dll" 19 | - vstest.console /logger:Appveyor /TestCaseFilter:"(TestCategory!=WebRequest)&(TestCategory!=Async)" "C:\projects\dotnet-threading\Tests\UnitTest.RackspaceThreading\bin\portable-net45\%CONFIGURATION%\UnitTest.RackspaceThreading.portable_net45.dll" 20 | - vstest.console /logger:Appveyor /TestCaseFilter:"(TestCategory!=WebRequest)&(TestCategory!=Async)" "C:\projects\dotnet-threading\Tests\UnitTest.RackspaceThreading\bin\portable-net40\%CONFIGURATION%\UnitTest.RackspaceThreading.portable_net40.dll" 21 | - vstest.console /logger:Appveyor /TestCaseFilter:"(TestCategory!=WebRequest)&(TestCategory!=Async)" "C:\projects\dotnet-threading\Tests\UnitTest.RackspaceThreading\bin\net40-client\%CONFIGURATION%\UnitTest.RackspaceThreading.net40.dll" 22 | - vstest.console /logger:Appveyor /TestCaseFilter:"(TestCategory!=WebRequest)&(TestCategory!=Async)" "C:\projects\dotnet-threading\Tests\UnitTest.RackspaceThreading\bin\net35-client\%CONFIGURATION%\UnitTest.RackspaceThreading.net35.dll" 23 | - vstest.console /logger:Appveyor /TestCaseFilter:"TestCategory=Async" "C:\projects\dotnet-threading\Tests\UnitTest.RackspaceThreading\bin\net45\%CONFIGURATION%\UnitTest.RackspaceThreading.net45.dll" 24 | - vstest.console /logger:Appveyor /TestCaseFilter:"TestCategory=Async" "C:\projects\dotnet-threading\Tests\UnitTest.RackspaceThreading\bin\portable-net45\%CONFIGURATION%\UnitTest.RackspaceThreading.portable_net45.dll" 25 | - vstest.console /logger:Appveyor /TestCaseFilter:"TestCategory=Async" "C:\projects\dotnet-threading\Tests\UnitTest.RackspaceThreading\bin\portable-net40\%CONFIGURATION%\UnitTest.RackspaceThreading.portable_net40.dll" 26 | - vstest.console /logger:Appveyor /TestCaseFilter:"TestCategory=Async" "C:\projects\dotnet-threading\Tests\UnitTest.RackspaceThreading\bin\net40-client\%CONFIGURATION%\UnitTest.RackspaceThreading.net40.dll" 27 | - vstest.console /logger:Appveyor /TestCaseFilter:"TestCategory=Async" "C:\projects\dotnet-threading\Tests\UnitTest.RackspaceThreading\bin\net35-client\%CONFIGURATION%\UnitTest.RackspaceThreading.net35.dll" 28 | after_test: 29 | - .\packages\OpenCover.4.6.166\tools\OpenCover.Console.exe -register:user -target:"vstest.console.exe" -targetargs:"/TestCaseFilter:(TestCategory!=WebRequest)&(TestCategory!=Async) C:\projects\dotnet-threading\Tests\UnitTest.RackspaceThreading\bin\net45\%CONFIGURATION%\UnitTest.RackspaceThreading.net45.dll" -filter:"+[Rackspace*]* +[UnitTest*]*" -excludebyattribute:*.ExcludeFromCodeCoverage* -hideskipped:All -output:.\Threading_coverage.xml 30 | - .\packages\OpenCover.4.6.166\tools\OpenCover.Console.exe -register:user -target:"vstest.console.exe" -targetargs:"/TestCaseFilter:(TestCategory!=WebRequest)&(TestCategory!=Async) C:\projects\dotnet-threading\Tests\UnitTest.RackspaceThreading\bin\portable-net45\%CONFIGURATION%\UnitTest.RackspaceThreading.portable_net45.dll" -filter:"+[Rackspace*]* +[UnitTest*]*" -excludebyattribute:*.ExcludeFromCodeCoverage* -hideskipped:All -output:.\Threading_coverage.xml -mergeoutput 31 | - .\packages\OpenCover.4.6.166\tools\OpenCover.Console.exe -register:user -target:"vstest.console.exe" -targetargs:"/TestCaseFilter:(TestCategory!=WebRequest)&(TestCategory!=Async) C:\projects\dotnet-threading\Tests\UnitTest.RackspaceThreading\bin\portable-net40\%CONFIGURATION%\UnitTest.RackspaceThreading.portable_net40.dll" -filter:"+[Rackspace*]* +[UnitTest*]*" -excludebyattribute:*.ExcludeFromCodeCoverage* -hideskipped:All -output:.\Threading_coverage.xml -mergeoutput 32 | - .\packages\OpenCover.4.6.166\tools\OpenCover.Console.exe -register:user -target:"vstest.console.exe" -targetargs:"/TestCaseFilter:(TestCategory!=WebRequest)&(TestCategory!=Async) C:\projects\dotnet-threading\Tests\UnitTest.RackspaceThreading\bin\net40-client\%CONFIGURATION%\UnitTest.RackspaceThreading.net40.dll" -filter:"+[Rackspace*]* +[UnitTest*]*" -excludebyattribute:*.ExcludeFromCodeCoverage* -hideskipped:All -output:.\Threading_coverage.xml -mergeoutput 33 | - .\packages\OpenCover.4.6.166\tools\OpenCover.Console.exe -register:user -target:"vstest.console.exe" -targetargs:"/TestCaseFilter:(TestCategory!=WebRequest)&(TestCategory!=Async) C:\projects\dotnet-threading\Tests\UnitTest.RackspaceThreading\bin\net35-client\%CONFIGURATION%\UnitTest.RackspaceThreading.net35.dll" -filter:"+[Rackspace*]* +[UnitTest*]*" -excludebyattribute:*.ExcludeFromCodeCoverage* -hideskipped:All -output:.\Threading_coverage.xml -mergeoutput 34 | - .\packages\OpenCover.4.6.166\tools\OpenCover.Console.exe -register:user -target:"vstest.console.exe" -targetargs:"/TestCaseFilter:TestCategory=Async C:\projects\dotnet-threading\Tests\UnitTest.RackspaceThreading\bin\net45\%CONFIGURATION%\UnitTest.RackspaceThreading.net45.dll" -filter:"+[Rackspace*]* +[UnitTest*]*" -excludebyattribute:*.ExcludeFromCodeCoverage* -hideskipped:All -output:.\Threading_coverage.xml -mergeoutput 35 | - .\packages\OpenCover.4.6.166\tools\OpenCover.Console.exe -register:user -target:"vstest.console.exe" -targetargs:"/TestCaseFilter:TestCategory=Async C:\projects\dotnet-threading\Tests\UnitTest.RackspaceThreading\bin\portable-net45\%CONFIGURATION%\UnitTest.RackspaceThreading.portable_net45.dll" -filter:"+[Rackspace*]* +[UnitTest*]*" -excludebyattribute:*.ExcludeFromCodeCoverage* -hideskipped:All -output:.\Threading_coverage.xml -mergeoutput 36 | - .\packages\OpenCover.4.6.166\tools\OpenCover.Console.exe -register:user -target:"vstest.console.exe" -targetargs:"/TestCaseFilter:TestCategory=Async C:\projects\dotnet-threading\Tests\UnitTest.RackspaceThreading\bin\portable-net40\%CONFIGURATION%\UnitTest.RackspaceThreading.portable_net40.dll" -filter:"+[Rackspace*]* +[UnitTest*]*" -excludebyattribute:*.ExcludeFromCodeCoverage* -hideskipped:All -output:.\Threading_coverage.xml -mergeoutput 37 | - .\packages\OpenCover.4.6.166\tools\OpenCover.Console.exe -register:user -target:"vstest.console.exe" -targetargs:"/TestCaseFilter:TestCategory=Async C:\projects\dotnet-threading\Tests\UnitTest.RackspaceThreading\bin\net40-client\%CONFIGURATION%\UnitTest.RackspaceThreading.net40.dll" -filter:"+[Rackspace*]* +[UnitTest*]*" -excludebyattribute:*.ExcludeFromCodeCoverage* -hideskipped:All -output:.\Threading_coverage.xml -mergeoutput 38 | - .\packages\OpenCover.4.6.166\tools\OpenCover.Console.exe -register:user -target:"vstest.console.exe" -targetargs:"/TestCaseFilter:TestCategory=Async C:\projects\dotnet-threading\Tests\UnitTest.RackspaceThreading\bin\net35-client\%CONFIGURATION%\UnitTest.RackspaceThreading.net35.dll" -filter:"+[Rackspace*]* +[UnitTest*]*" -excludebyattribute:*.ExcludeFromCodeCoverage* -hideskipped:All -output:.\Threading_coverage.xml -mergeoutput 39 | - "SET PATH=C:\\Python34;C:\\Python34\\Scripts;%PATH%" 40 | - pip install codecov 41 | - codecov -f "Threading_coverage.xml" 42 | # preserve "packages" directory in the root of build folder but will reset it if packages.config is modified 43 | cache: 44 | - packages -> **\packages.config 45 | - .shfb -> build\build.ps1 46 | -------------------------------------------------------------------------------- /stylecop.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", 3 | "settings": { 4 | "documentationRules": { 5 | "companyName": "Tunnel Vision Laboratories, LLC", 6 | "copyrightText": "Copyright (c) {companyName}. All Rights Reserved.\nLicensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.", 7 | "xmlHeader": false, 8 | "fileNamingConvention": "metadata" 9 | }, 10 | "layoutRules": { 11 | "newlineAtEndOfFile": "require" 12 | } 13 | } 14 | } 15 | --------------------------------------------------------------------------------