Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / January 2008

Tip: Looking for answers? Try searching our database.

Increasing Stack Size for UI Thread: C# WinForms Application

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
randy1200 - 11 Jan 2008 17:03 GMT
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
Willy Denoyette [MVP] - 11 Jan 2008 17:21 GMT
> Visual Studio 2005, C# WinForms application:
>
[quoted text clipped - 28 lines]
> 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.
randy1200 - 11 Jan 2008 17:43 GMT
That was exactly what I needed. Many thanks!

Randy

> > Visual Studio 2005, C# WinForms application:
> >
[quoted text clipped - 35 lines]
>
> Willy.
Nicholas Paldino [.NET/C# MVP] - 11 Jan 2008 17:29 GMT
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.

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> Visual Studio 2005, C# WinForms application:
>
[quoted text clipped - 28 lines]
> Thanks,
> Randy
randy1200 - 11 Jan 2008 18:33 GMT
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.

> Randy,
>
[quoted text clipped - 40 lines]
> > Thanks,
> > Randy

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.