How can I find current thread\'s maximum stack size?
I am getting a stack overflow exception while executing a function from MMC UI but not from Powershell (command-
Getting this information is a real PITA actually:
ThreadBasicInformation as THREADINFOCLASS to get a THREAD_BASIC_INFORMATION structure. You now have the TebBaseAddress parameter that is the address of the Thread Environment Block.TebBaseAddress address.StackLimit property which is the value you're looking for.From step 3, it's undocumented. That's why I do not recommend retrieving this information.
From Windows 8, there is the GetCurrentThreadStackLimits() function. You can use it from C# via PInvoke like this:
[DllImport("kernel32.dll")]
static extern void GetCurrentThreadStackLimits(out uint lowLimit, out uint highLimit);
uint low;
uint high;
GetCurrentThreadStackLimits(out low, out high);
var size = (high - low) / 1024; // in KB
On my machine, this yields 1MB in a console application, 256KB in a web application (IIS).