Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am JeffCyr on github.
  • I am jeffcyr (https://keybase.io/jeffcyr) on keybase.
  • I have a public key whose fingerprint is ED99 66CA 462F 2270 B5A3 11E6 9D80 F1B3 34BF C1B9

To claim this, I am signing this object:

@JeffCyr
JeffCyr / Program.cs
Last active May 25, 2016 01:47
Alignment
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
namespace Alignment
{
public class MemoryAlignmentAttribute : Attribute
@JeffCyr
JeffCyr / AwaitContinuationThread.cs
Last active October 24, 2018 12:02
Tpl Pitfals
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace TplPitfalls
{
public class SingleThreadTaskScheduler : TaskScheduler
{
@JeffCyr
JeffCyr / TaskSchedulerBenchmark.cs
Last active March 10, 2016 18:23
TaskScheduler creation benchmark
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
namespace TaskSchedulerBenchmark
{
public class CustomTaskScheduler : TaskScheduler
@JeffCyr
JeffCyr / CallContextBug.cs
Last active March 10, 2016 18:24
Demonstration that CallContext is not set in TaskScheduler.QueueTask
void Main()
{
var testScheduler = new TestTaskScheduler();
CallContext.LogicalSetData("foo", "bar");
Task.Run(() =>
{
CallContext.LogicalGetData("foo").Dump("Task.Run");
}).ContinueWith(_ =>
@JeffCyr
JeffCyr / TaskSchedulerAwaiter
Created April 10, 2015 17:01
Allows an async method to await a TaskScheduler and continue the execution in it.
public static class TaskEx
{
/// <summary>
/// Continue the execution on the specified TaskScheduler.
/// The awaiter will be synchronous if the current TaskScheduler
/// is the specified TaskScheduler.
/// </summary>
public sealed class TaskSchedulerAwaiter : INotifyCompletion
{
private TaskFactory m_factory;