Skip to content

Instantly share code, notes, and snippets.

@lazyval
Created January 22, 2012 22:30
Show Gist options
  • Save lazyval/1659150 to your computer and use it in GitHub Desktop.
Save lazyval/1659150 to your computer and use it in GitHub Desktop.
An example of extension methods in C#
using System;
using System.Collections.Concurrent;
using System.Threading;
namespace ReadWriteBuffer
{
public static class ThreadExtension
{
private const LocalDataStoreSlot PRIORITY_SLOT = Thread.GetNamedDataSlot("prioritySlot");
public static ThreadPriority GetPriority(this Thread t)
{
object data = Thread.GetData(PRIORITY_SLOT);
return (data == null) ?
ThreadPriority.Normal : (ThreadPriority)data;
}
public static void SetPriority(this Thread t, ThreadPriority p)
{
Thread.SetData(PRIORITY_SLOT, p);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment