Created
January 22, 2012 22:30
-
-
Save lazyval/1659150 to your computer and use it in GitHub Desktop.
An example of extension methods in C#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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