Skip to content

Instantly share code, notes, and snippets.

View StephenCleary's full-sized avatar

Stephen Cleary StephenCleary

View GitHub Profile
@StephenCleary
StephenCleary / Program.cs
Created February 14, 2012 14:34
Coroutines in VS11
using System;
using System.Linq;
using System.Threading.Tasks;
// Target: .NET 4.5 Client (or Full)
// Add a reference to System.Threading.Tasks.Dataflow
class Program
{
static void Main(string[] args)
@StephenCleary
StephenCleary / AsyncLazy.cs
Created September 23, 2012 22:15
AsyncLazy
using System;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
/// <summary>
/// Provides support for asynchronous lazy initialization. This type is fully threadsafe.
/// </summary>
/// <typeparam name="T">The type of object that is being asynchronously initialized.</typeparam>
public sealed class AsyncLazy<T>
{
@StephenCleary
StephenCleary / Output
Created March 7, 2013 15:07
Task identifiers are not unique. On my machine, this program will run for 3 minutes and then produce the output.
Id collision!
task.Id == other.Id: True
task == other: False
@StephenCleary
StephenCleary / Program.cs
Created May 3, 2013 00:06
To search for asynchronous APIs, create a console app with this code. Reference all dlls you want to search, and then run the app in the debugger.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
namespace DisplayAsyncAPIs
{
class Program
@StephenCleary
StephenCleary / Async WebAPI
Last active April 17, 2020 03:05
Simple WebAPI app with Console client that shows that async methods do release threads to the thread pool.
Simple WebAPI app with Console client that shows that async methods do release threads to the thread pool.
@StephenCleary
StephenCleary / gist:6794708
Last active December 24, 2015 11:59 — forked from anonymous/gist:6782497
500 Internal Server Error for the request "https://www.healthcare.gov/ee-rest/ffe/en_US/MyAccountEIDMUnsecuredIntegration/fetchAllSecurityQuestions/ffm" which is silently ignored by the JavaScript and results in no security questions in the dropdowns. Site has been down 34.5 hours and counting... The error message has been updated today with pre…
java.lang.RuntimeException: org.apache.cxf.interceptor.Fault: Could not send Message.
org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:110)
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:323)
org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:123)
org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:207)
org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:213)
org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:154)
org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:126)
org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:185)
org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPServlet.java:113)
@StephenCleary
StephenCleary / ObserverProgress.cs
Created November 6, 2013 03:23
ObserverProgress: An IProgress implementation that forwards to an IObserver.
using System;
using System.Threading.Tasks;
namespace Nito.AsyncEx
{
/// <summary>
/// A progress implementation that sends progress reports to an observer stream. Optionally ends the stream when the task completes.
/// </summary>
/// <typeparam name="T">The type of progress value.</typeparam>
internal sealed class ObserverProgress<T> : IProgress<T>
@StephenCleary
StephenCleary / Program.cs
Last active December 30, 2015 21:59
Serialization size test for Azure caching. Requires NuGet packages: Comparers, Newtonsoft.Json
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using Comparers;
@StephenCleary
StephenCleary / LinkedDic.cs
Last active December 31, 2015 04:09 — forked from ayende/LinkedDic.cs
Added tests with Builder, SortedImmutableDictionary, and LinkedDictionaryUnoptimized.
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace Voron.Util
{
public class LinkedDictionary<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>, IReadOnlyDictionary<TKey, TValue>
where TValue : class, new()
{
private readonly TValue _deleteMarker = new TValue();
@StephenCleary
StephenCleary / ObservableProgress.cs
Last active April 16, 2024 11:22
ObservableProgress
using System;
using System.Reactive.Linq;
using System.Threading;
/// <summary>
/// Helper methods for using observable <see cref="IProgress{T}"/> implementations. These are hot observables.
/// </summary>
public static class ObservableProgress
{
/// <summary>