Created
December 5, 2015 11:54
-
-
Save adbre/112834a37d4706266d62 to your computer and use it in GitHub Desktop.
This file contains 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.Threading; | |
namespace Example | |
{ | |
public static class ThreadPond | |
{ | |
public static void QueueUserWorkItem<T1>(Action<T1> callback, T1 arg1) | |
{ | |
if (callback == null) throw new ArgumentNullException(nameof(callback)); | |
ThreadPool.QueueUserWorkItem(state => | |
{ | |
callback((T1)state); | |
}, arg1); | |
} | |
public static void QueueUserWorkItem<T1, T2>(Action<T1, T2> callback, T1 arg1, T2 arg2) | |
{ | |
if (callback == null) throw new ArgumentNullException(nameof(callback)); | |
QueueUserWorkItem(tuple => | |
{ | |
callback(tuple.Item1, tuple.Item2); | |
}, new Tuple<T1, T2>(arg1, arg2)); | |
} | |
public static void QueueUserWorkItem<T1, T2, T3>(Action<T1, T2, T3> callback, T1 arg1, T2 arg2, T3 arg3) | |
{ | |
if (callback == null) throw new ArgumentNullException(nameof(callback)); | |
QueueUserWorkItem(tuple => | |
{ | |
callback(tuple.Item1, tuple.Item2, tuple.Item3); | |
}, new Tuple<T1, T2, T3>(arg1, arg2, arg3)); | |
} | |
public static void QueueUserWorkItem<T1, T2, T3, T4>(Action<T1, T2, T3, T4> callback, T1 arg1, T2 arg2, T3 arg3, T4 arg4) | |
{ | |
if (callback == null) throw new ArgumentNullException(nameof(callback)); | |
QueueUserWorkItem(tuple => | |
{ | |
callback(tuple.Item1, tuple.Item2, tuple.Item3, tuple.Item4); | |
}, new Tuple<T1, T2, T3, T4>(arg1, arg2, arg3, arg4)); | |
} | |
public static void QueueUserWorkItem<T1, T2, T3, T4, T5>(Action<T1, T2, T3, T4, T5> callback, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) | |
{ | |
if (callback == null) throw new ArgumentNullException(nameof(callback)); | |
QueueUserWorkItem(tuple => | |
{ | |
callback(tuple.Item1, tuple.Item2, tuple.Item3, tuple.Item4, tuple.Item5); | |
}, new Tuple<T1, T2, T3, T4, T5>(arg1, arg2, arg3, arg4, arg5)); | |
} | |
public static void QueueUserWorkItem<T1, T2, T3, T4, T5, T6>(Action<T1, T2, T3, T4, T5, T6> callback, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6) | |
{ | |
if (callback == null) throw new ArgumentNullException(nameof(callback)); | |
QueueUserWorkItem(tuple => | |
{ | |
callback(tuple.Item1, tuple.Item2, tuple.Item3, tuple.Item4, tuple.Item5, tuple.Item6); | |
}, new Tuple<T1, T2, T3, T4, T5, T6>(arg1, arg2, arg3, arg4, arg5, arg6)); | |
} | |
public static void QueueUserWorkItem<T1, T2, T3, T4, T5, T6, T7>(Action<T1, T2, T3, T4, T5, T6, T7> callback, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7) | |
{ | |
if (callback == null) throw new ArgumentNullException(nameof(callback)); | |
QueueUserWorkItem(tuple => | |
{ | |
callback(tuple.Item1, tuple.Item2, tuple.Item3, tuple.Item4, tuple.Item5, tuple.Item6, tuple.Item7); | |
}, new Tuple<T1, T2, T3, T4, T5, T6, T7>(arg1, arg2, arg3, arg4, arg5, arg6, arg7)); | |
} | |
public static void QueueUserWorkItem<T1, T2, T3, T4, T5, T6, T7, TRest>(Action<T1, T2, T3, T4, T5, T6, T7, TRest> callback, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, TRest rest) | |
{ | |
if (callback == null) throw new ArgumentNullException(nameof(callback)); | |
QueueUserWorkItem(tuple => | |
{ | |
callback(tuple.Item1, tuple.Item2, tuple.Item3, tuple.Item4, tuple.Item5, tuple.Item6, tuple.Item7, tuple.Rest); | |
}, new Tuple<T1, T2, T3, T4, T5, T6, T7, TRest>(arg1, arg2, arg3, arg4, arg5, arg6, arg7, rest)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment