How to create a new Thread to execute an Action<T>
I wouldn't even bother with ParameterizedThreadStart
. Let the compiler do the dirty work:
private void ExecuteInBiggerStackThread(Action<Helper> action, Helper h){ Thread bigStackThread = new Thread(() => action(h), 1024 * 1024); bigStackThread.Start(); bigStackThread.Join();}
Of course, you could carry this a step further and change the signature to:
private void ExecuteInBiggerStackThread(Action action) { ... }
Something like this ought to do the trick:
private void ExecuteInBiggerStackThread(Action<Helper> action, Helper h){ var operation = new ParameterizedThreadStart(obj => action((Helper)obj)); Thread bigStackThread = new Thread(operation, 1024 * 1024); bigStackThread.Start(h); bigStackThread.Join();}
Or a more generic version of the method....
protected void ExecuteInBiggerStackThread<T>(Action<T> action, T parameterObject){ var bigStackThread = new Thread(() => action(parameterObject), 1024 * 1024); bigStackThread.Start(); bigStackThread.Join();}