Last active
December 17, 2015 02:39
-
-
Save Konard/5537926 to your computer and use it in GitHub Desktop.
ThreadArrayExtensions is static class (module) containing extension-methods for System.Threading.Thread[] type.
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 Helpers | |
{ | |
public static class ThreadArrayExtensions | |
{ | |
public static Thread[] StartAll(this Thread[] threads, params object[] values) | |
{ | |
if (values.Length == 0) | |
{ | |
for (int i = 0; i < threads.Length; i++) | |
threads[i].Start(); | |
} | |
else if (values.Length == 1) | |
{ | |
for (int i = 0; i < threads.Length; i++) | |
threads[i].Start(values[0]); | |
} | |
else | |
{ | |
for (int i = 0; i < threads.Length; i++) | |
threads[i].Start(values[i]); | |
} | |
return threads; | |
} | |
public static Thread[] WaitAll(this Thread[] threads) | |
{ | |
for (int i = 0; i < threads.Length; i++) | |
threads[i].Join(); | |
return threads; | |
} | |
public static Thread[] WaitAll(this Thread[] threads, TimeSpan timeout) | |
{ | |
for (int i = 0; i < threads.Length; i++) | |
threads[i].Join(timeout); | |
return threads; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment