473,320 Members | 1,902 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Increasing Stack Size for UI Thread: C# WinForms Application

Visual Studio 2005, C# WinForms application:

Here’s the question: How can I increase the standard 1 MB stack size of the
UI thread in a C# WinForms application?

Here’s why I ask:

I’ve inherited some code that at the view (User Interface) layer kicks off a
background worker thread. At the service layer (think CAB service layer),
there’s quite a lot of the following:

worker.ReportProgress(n, new string[] { cat, mesg });

The _BackgroundWorker_ProgressChanged() event gets these events, and does a
large amount of string processing. When the user chooses to process all
available data, the _ProgressChanged() event eventually throws a
StackOverflow exception with the following in the details section:

"Cannot evaluate expression because the current thread is in a stack
overflow state."

If I take the string processing out of the _ProgressChanged() event, I don’t
get the StackOverflow, so I’m pretty confident that I’ve isolated the
problem. Increasing the stack size if definitely a temp fix, but something I
need to consider in the short term.

Thanks,
Randy

Jan 11 '08 #1
4 6310
"randy1200" <ra*******@discussions.microsoft.comwrote in message
news:61**********************************@microsof t.com...
Visual Studio 2005, C# WinForms application:

Here’s the question: How can I increase the standard 1 MB stack size of
the
UI thread in a C# WinForms application?

Here’s why I ask:

I’ve inherited some code that at the view (User Interface) layer kicks off
a
background worker thread. At the service layer (think CAB service layer),
there’s quite a lot of the following:

worker.ReportProgress(n, new string[] { cat, mesg });

The _BackgroundWorker_ProgressChanged() event gets these events, and does
a
large amount of string processing. When the user chooses to process all
available data, the _ProgressChanged() event eventually throws a
StackOverflow exception with the following in the details section:

"Cannot evaluate expression because the current thread is in a stack
overflow state."

If I take the string processing out of the _ProgressChanged() event, I don’t
get the StackOverflow, so I’m pretty confident that I’ve isolated the
problem. Increasing the stack size if definitely a temp fix, but something
I
need to consider in the short term.

Thanks,
Randy

Using "editbin /stack" allows you to set the stack size for all threads in
the process.
running "editbin /stack:2000000 some.exe"
will set the default stack (reserve) to 2000000 bytes.

Willy.

Jan 11 '08 #2
Randy,

Do you have any recursive calls here? The StackOverflowException occurs
when you have a very deep call stack, and I doubt that you are doing
non-recursive calls which are testing this limit.

I am almost certain it is a recursion issue, and if you find where you
are making an unbounded recursive call, you will fix the issue.

Assuming this is the case, increasing the call stack in this case will
do nothing for you.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"randy1200" <ra*******@discussions.microsoft.comwrote in message
news:61**********************************@microsof t.com...
Visual Studio 2005, C# WinForms application:

Here's the question: How can I increase the standard 1 MB stack size of
the
UI thread in a C# WinForms application?

Here's why I ask:

I've inherited some code that at the view (User Interface) layer kicks off
a
background worker thread. At the service layer (think CAB service layer),
there's quite a lot of the following:

worker.ReportProgress(n, new string[] { cat, mesg });

The _BackgroundWorker_ProgressChanged() event gets these events, and does
a
large amount of string processing. When the user chooses to process all
available data, the _ProgressChanged() event eventually throws a
StackOverflow exception with the following in the details section:

"Cannot evaluate expression because the current thread is in a stack
overflow state."

If I take the string processing out of the _ProgressChanged() event, I don't
get the StackOverflow, so I'm pretty confident that I've isolated the
problem. Increasing the stack size if definitely a temp fix, but something
I
need to consider in the short term.

Thanks,
Randy

Jan 11 '08 #3
That was exactly what I needed. Many thanks!

Randy

"Willy Denoyette [MVP]" wrote:
"randy1200" <ra*******@discussions.microsoft.comwrote in message
news:61**********************************@microsof t.com...
Visual Studio 2005, C# WinForms application:

Here’s the question: How can I increase the standard 1 MB stack size of
the
UI thread in a C# WinForms application?

Here’s why I ask:

I’ve inherited some code that at the view (User Interface) layer kicks off
a
background worker thread. At the service layer (think CAB service layer),
there’s quite a lot of the following:

worker.ReportProgress(n, new string[] { cat, mesg });

The _BackgroundWorker_ProgressChanged() event gets these events, and does
a
large amount of string processing. When the user chooses to process all
available data, the _ProgressChanged() event eventually throws a
StackOverflow exception with the following in the details section:

"Cannot evaluate expression because the current thread is in a stack
overflow state."

If I take the string processing out of the _ProgressChanged() event, I don’t
get the StackOverflow, so I’m pretty confident that I’ve isolated the
problem. Increasing the stack size if definitely a temp fix, but something
I
need to consider in the short term.

Thanks,
Randy


Using "editbin /stack" allows you to set the stack size for all threads in
the process.
running "editbin /stack:2000000 some.exe"
will set the default stack (reserve) to 2000000 bytes.

Willy.

Jan 11 '08 #4
Many thanks for the response. Increasing the stack size did eliminate the
StackOverflow exception. When I reset the stack size back to 1 MB using
editbin and reran, the stack overflow exception returned.

To widen the scope a bit, the background_worker thread actually passes a
list of "customers" to a be queued to a threadpool to be "processed." The
threadpool does a great job of throttling itself as it works through the
list. When the threadpool threads complete, a lot (many hundreds) of
worker.ReportProgress() calls are sending text back to
_BackgroundWorker_ProgressChanged(), which is in turn doing a lot of string
processing. I think ultimately, the right answer is to do all the string
processing on the threadpool threads. _BackgroundWorker_ProgressChanged()
does not seem to have any problems if it's only task is to assign text to a
UI display control.

"Nicholas Paldino [.NET/C# MVP]" wrote:
Randy,

Do you have any recursive calls here? The StackOverflowException occurs
when you have a very deep call stack, and I doubt that you are doing
non-recursive calls which are testing this limit.

I am almost certain it is a recursion issue, and if you find where you
are making an unbounded recursive call, you will fix the issue.

Assuming this is the case, increasing the call stack in this case will
do nothing for you.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"randy1200" <ra*******@discussions.microsoft.comwrote in message
news:61**********************************@microsof t.com...
Visual Studio 2005, C# WinForms application:

Here's the question: How can I increase the standard 1 MB stack size of
the
UI thread in a C# WinForms application?

Here's why I ask:

I've inherited some code that at the view (User Interface) layer kicks off
a
background worker thread. At the service layer (think CAB service layer),
there's quite a lot of the following:

worker.ReportProgress(n, new string[] { cat, mesg });

The _BackgroundWorker_ProgressChanged() event gets these events, and does
a
large amount of string processing. When the user chooses to process all
available data, the _ProgressChanged() event eventually throws a
StackOverflow exception with the following in the details section:

"Cannot evaluate expression because the current thread is in a stack
overflow state."

If I take the string processing out of the _ProgressChanged() event, I don't
get the StackOverflow, so I'm pretty confident that I've isolated the
problem. Increasing the stack size if definitely a temp fix, but something
I
need to consider in the short term.

Thanks,
Randy


Jan 11 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: RA Scheltema | last post by:
hi there, I'm working on a project in Visual Basic .NET, which makes use of a dll that rquires quite a lot of stack space. Is there a way to increase the available stack space (about 10 mb...
13
by: Ben R. Bolton | last post by:
The documentation indicates that the threads "default stack size" is 1MB. The work "default" implies that it can be changed. Is it possible to change the StackSize in .NET? If so how? Is it...
7
by: Doug Thews | last post by:
I saw something interesting when testing my multi-threaded code to make sure that threads were terminating as I expected. When I first bring up my WinForms test application (before I do any...
2
by: Darryn | last post by:
Hi Please help... i am running an application where one of my data validation funtions linked to a Dataset event ColumnChanging keeps throwing a StackOverflowException!!! My code is fine, i...
9
by: shine | last post by:
what is the difference between a heap and a stack?
5
by: jbix | last post by:
We have a stack overflow happening. We are NOT doing any recusion. We do have an object being created in Global that is being handed the Context (which I assume is specific to the request thread). ...
9
by: Ajay | last post by:
Hi all, Can I know what is the stack space and heap space allocated by the compiler.Can i increase it or decrease it.if yes,pleae tell me theway to do it.Thanks in advance. Cheers, Ajay
2
by: Amit Dedhia | last post by:
Hi I am developing a scientific application which has moderate level image processing involved. In my application, there is a main application form which invokes another form. When this form...
9
by: Jensen Somers | last post by:
Hi, Is it possible to change the stack size of a DLL from within the source code? When using threads you can specify the size of the stack you want the thread to use, but since my application...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.