.NET Framework Class Library
Thread Constructor (ThreadStart, Int32)

Initializes a new instance of the Thread class, specifying the maximum stack size for the thread.

Namespace:  System.Threading
Assembly:  mscorlib (in mscorlib.dll)
Syntax

Visual Basic (Declaration)
Public Sub New ( _
    start As ThreadStart, _
    maxStackSize As Integer _
)
Visual Basic (Usage)
Dim start As ThreadStart
Dim maxStackSize As Integer

Dim instance As New Thread(start, maxStackSize)
C#
public Thread(
    ThreadStart start,
    int maxStackSize
)
Visual C++
public:
Thread(
    ThreadStart^ start, 
    int maxStackSize
)
JScript
public function Thread(
    start : ThreadStart, 
    maxStackSize : int
)

Parameters

start
Type: System.Threading..::.ThreadStart
A ThreadStart delegate that represents the methods to be invoked when this thread begins executing.
maxStackSize
Type: System..::.Int32
The maximum stack size to be used by the thread, or 0 to use the default maximum stack size specified in the header for the executable.
Exceptions

ExceptionCondition
ArgumentNullException

start is nullNothingnullptra null reference (Nothing in Visual Basic).

ArgumentOutOfRangeException

maxStackSize is less than zero.

Remarks

Avoid using this constructor overload. The default stack size used by the Thread(ThreadStart) constructor overload is the recommended stack size for threads. If a thread has memory problems, the most likely cause is programming error, such as infinite recursion.

If maxStackSize is less than the minimum stack size, the minimum stack size is used. If maxStackSize is not a multiple of the page size, it is rounded to the next larger multiple of the page size. For example, if you are using the .NET Framework version 2.0 on Microsoft Windows Vista, 256KB (262144 bytes) is the minimum stack size, and the page size is 64KB (65536 bytes).

NoteNote:

On versions of Microsoft Windows prior to Windows XP and Windows Server 2003, maxStackSize is ignored, and the stack size specified in the executable header is used.

If you specify a very small stack size, you might need to disable stack-overflow probing. When the stack is severely constrained, the probing can itself cause a stack overflow. To disable stack overflow probing, add the following to your application configuration file.

<configuration>
  <runtime>
    <disableStackOverflowProbing enabled="true"/>
  </runtime>
</configuration>
Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0, 2.0

.NET Compact Framework

Supported in: 3.5, 2.0

XNA Framework

Supported in: 3.0, 2.0, 1.0
See Also

Reference



Community Content

Ravi KP
StackOverflowException
we have a legacy function that we translated to .net and it came out to more than 5000 lines and the call stack is very deep. In this process when this large method is being called(during the jit process), we get can a stackoverflow exception in .NET 2.0 64 bit, but the same code works fine in 32 bit. I went ahead and added this <disableStackOverflowProbing enabled="true"/> to the runtime element in the configuration file. This made the application runt in 64 bit smoothly

Page view tracker