Skip to content

Instantly share code, notes, and snippets.

@konard
Created May 8, 2013 03:12
Show Gist options
  • Save konard/5537930 to your computer and use it in GitHub Desktop.
Save konard/5537930 to your computer and use it in GitHub Desktop.
ThreadHelpers is a static class (module) containing utility methods to deal with System.Threading.Thread class.
using System.Threading;
namespace Helpers
{
public static class ThreadHelpers
{
public static Thread[] CreateThreads(ThreadStart action, int amount, int maxStackSize)
{
Thread[] threads = new Thread[amount];
for (int i = 0; i < threads.Length; i++)
threads[i] = new Thread(action, maxStackSize);
return threads;
}
public static Thread[] CreateThreads(ThreadStart action, int amount)
{
Thread[] threads = new Thread[amount];
for (int i = 0; i < threads.Length; i++)
threads[i] = new Thread(action);
return threads;
}
public static Thread[] CreateThreads(ParameterizedThreadStart function, int amount, int maxStackSize)
{
Thread[] threads = new Thread[amount];
for (int i = 0; i < threads.Length; i++)
threads[i] = new Thread(function, maxStackSize);
return threads;
}
public static Thread[] CreateThreads(ParameterizedThreadStart function, int amount)
{
Thread[] threads = new Thread[amount];
for (int i = 0; i < threads.Length; i++)
threads[i] = new Thread(function);
return threads;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment