473,395 Members | 1,530 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,395 software developers and data experts.

Handler Stack Overflow?!?!

Please help!

I have a handler in a class that handles when a column in a table is
modified, as such:

dtWhatif = dsOp.Tables("whatif")
AddHandler dtWhatif.ColumnChanged, New
DataColumnChangeEventHandler(AddressOf Whatif_Changed)

When testing this, I got an error: An unhandled exception of type
'System.StackOverflowException' occurred in system.dll

So I put a debug statement in to see why the stack is overflowing. This
handler was called 4082 times! All I did was change the value in one
cell of a datagrid!

Why?! Why?!

Tom

Nov 21 '05 #1
10 1929
> dtWhatif = dsOp.Tables("whatif")
AddHandler dtWhatif.ColumnChanged, New
DataColumnChangeEventHandler(AddressOf Whatif_Changed)


What happens in Whatif_Changed?

Nov 21 '05 #2
Right now, it just calls and empty function. I was just testing the
handler, and found it doesn't work as expected.

Tom

Chris Dunaway wrote:
dtWhatif = dsOp.Tables("whatif")
AddHandler dtWhatif.ColumnChanged, New
DataColumnChangeEventHandler(AddressOf Whatif_Changed)


What happens in Whatif_Changed?

Nov 21 '05 #3
I just tried commenting out the call to the other function from within
the event handler. Guess what? No problem. I only get the stack
overload if the handler calls another function. This is not a good
thing, because I need to be able to call several functions when the
column has changed. Any suggestions?

Tom

Chris Dunaway wrote:
dtWhatif = dsOp.Tables("whatif")
AddHandler dtWhatif.ColumnChanged, New
DataColumnChangeEventHandler(AddressOf Whatif_Changed)


What happens in Whatif_Changed?

Nov 21 '05 #4
What Chris meant was please post your code. You have obviously generated some race condition here.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"tomb" <to**@technetcenter.com> wrote in message news:6b*****************@bignews3.bellsouth.net...
I just tried commenting out the call to the other function from within the event handler. Guess what? No problem. I only get the stack overload if the handler calls another function. This is not a good thing, because I need to be able to call several functions when the column has changed. Any suggestions?

Tom

Chris Dunaway wrote:

dtWhatif = dsOp.Tables("whatif")
AddHandler dtWhatif.ColumnChanged, New
DataColumnChangeEventHandler(AddressOf Whatif_Changed)


What happens in Whatif_Changed?



Nov 21 '05 #5
Ok, here's the code:
Private Sub Whatif_Changed(ByVal sender As Object, ByVal e As
DataColumnChangeEventArgs)
Static i As Integer = 0
'I added i for the debugger
i += 1

Debug.WriteLine("This is cycle number " & i)
calcWhatif(e.Column.ColumnName, e.Row.Item(0))
'if calcWhatif is commented out, then this handler is called once,
otherwise it just keeps being called and the next
debug line never fires - the call stack overloads first.

Debug.WriteLine("Column " & e.Column.Ordinal)

End Sub

Right now, calcWhatif doesn't do anything. The code that was going to
be there can go in the handler, but I still will need to call other
functions as part of that calculation.

Thanks for any clarification you can provide.

Tom

Bob Powell [MVP] wrote:
What Chris meant was please post your code. You have obviously
generated some race condition here.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.


"tomb" <to**@technetcenter.com <mailto:to**@technetcenter.com>>
wrote in message news:6b*****************@bignews3.bellsouth.net...
I just tried commenting out the call to the other function from
within the event handler. Guess what? No problem. I only get
the stack overload if the handler calls another function. This is
not a good thing, because I need to be able to call several
functions when the column has changed. Any suggestions?

Tom

Chris Dunaway wrote:
dtWhatif = dsOp.Tables("whatif")
AddHandler dtWhatif.ColumnChanged, New
DataColumnChangeEventHandler(AddressOf Whatif_Changed)


What happens in Whatif_Changed?

Nov 21 '05 #6
tomb wrote:
calcWhatif(e.Column.ColumnName, e.Row.Item(0))
Debug.WriteLine("Column " & e.Column.Ordinal)

Right now, calcWhatif doesn't do anything. The code that was going to


Does calcWhatif have any code in it at all? The behavior you are
describing sounds like the calcWhatif method is changing the column
which in turn causes the column changed event to fire which executes
calcWhatif which changes the column which in turn causes the column
changed event to fire and on and on until the stack over flows.

What you can try is declaring a boolean property outside the method,
for example called bColumnChanging. Then, inside the event, you check
that boolean:

If Not bColumnChanging Then
bColumnChanging = True

'...rest of code here

bColumnChanging = False
End If

But first you should determine exactly why the stack is overflowing.

Nov 21 '05 #7
This wouldn't cause a stack overflow. Just the efficient eating up of 100%
of the processor. It sounds to me as if CalcWhatIf calls CalcWhatIf
internally and is causing a recursive problem.

If however the OP refuses to post the actual code instead of being all coy
about the content of his method then there's not a whole lot we can do ;-)

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Chris Dunaway" <du******@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
tomb wrote:
calcWhatif(e.Column.ColumnName, e.Row.Item(0))
Debug.WriteLine("Column " & e.Column.Ordinal)

Right now, calcWhatif doesn't do anything. The code that was going to


Does calcWhatif have any code in it at all? The behavior you are
describing sounds like the calcWhatif method is changing the column
which in turn causes the column changed event to fire which executes
calcWhatif which changes the column which in turn causes the column
changed event to fire and on and on until the stack over flows.

What you can try is declaring a boolean property outside the method,
for example called bColumnChanging. Then, inside the event, you check
that boolean:

If Not bColumnChanging Then
bColumnChanging = True

'...rest of code here

bColumnChanging = False
End If

But first you should determine exactly why the stack is overflowing.

Nov 21 '05 #8
I told you already, calcWhatif doesn't do anything yet. I haven't put
any code in it other than this:

Private Sub calcWhatif(ByRef sColumn As String, ByRef iRow As String)

Dim dr As DataRow
Dim drW As DataRow
Dim ProdPos As ProductPosition 'a small defined class object

Static i As Integer = 0

i += 1

Debug.WriteLine("calcWhatif " & i)

End Sub

I added the debug piece to help me see what was going on.

The handler is as follows:

Private Sub Whatif_Changed(ByVal sender As Object, ByVal e As
DataColumnChangeEventArgs)

Static i As Integer = 0

i += 1

Debug.WriteLine("This is cycle number " & i)

calcWhatif(e.Column.ColumnName, e.Row.Item(0))
Debug.WriteLine("Column " & e.Column.Ordinal)

End Sub

So, right now the handler is calling an empty function that just returns
after outputting the debug info. The problem is that the handler is
being called again before returniing from calcWhatif to run the second
debug line. I never get to see the column ordinal displayed.

But if I take out the call to calcWhatif, everything is fine - I see the
ordinal value and the handler runs once. This handler has to be able to
call another function, because I have to run calculations based on the
changed value.

Any insight?

Tom
Bob Powell [MVP] wrote:
This wouldn't cause a stack overflow. Just the efficient eating up of 100%
of the processor. It sounds to me as if CalcWhatIf calls CalcWhatIf
internally and is causing a recursive problem.

If however the OP refuses to post the actual code instead of being all coy
about the content of his method then there's not a whole lot we can do ;-)

Nov 21 '05 #9
Would you believe it, when I changed the parameters to being passed
byVal, everything was fine. Something to take note of for event
handlers - calling another function ByRef explodes!

Tom

Bob Powell [MVP] wrote:
This wouldn't cause a stack overflow. Just the efficient eating up of 100%
of the processor. It sounds to me as if CalcWhatIf calls CalcWhatIf
internally and is causing a recursive problem.

If however the OP refuses to post the actual code instead of being all coy
about the content of his method then there's not a whole lot we can do ;-)

Nov 21 '05 #10
Tomb,
You also need to be very careful which changing a the value of a column on a
row, in the ColumnChanged event handler, as this will cause the event to be
raised, which will cause the handler to be called, causing the row to be
changed causing the event to be raised, causing the handler to be called,
causing the row to be changed, causing the event to be raised, causing ...
.... causing Stack Overflow...

I normally put a "guard" condition in my handler to exit the handler if a
column I am not interested (such as the column I am about to change) has
changed... Alternatively I will check to see if only the columns I am
interested in have changed, such as the columns that are input into a
formula I am calculating in the ColumnChanged event...

Hope this helps
Jay

"tomb" <to**@technetcenter.com> wrote in message
news:JP******************@bignews5.bellsouth.net.. .
| Would you believe it, when I changed the parameters to being passed
| byVal, everything was fine. Something to take note of for event
| handlers - calling another function ByRef explodes!
|
| Tom
|
| Bob Powell [MVP] wrote:
|
| >This wouldn't cause a stack overflow. Just the efficient eating up of
100%
| >of the processor. It sounds to me as if CalcWhatIf calls CalcWhatIf
| >internally and is causing a recursive problem.
| >
| >If however the OP refuses to post the actual code instead of being all
coy
| >about the content of his method then there's not a whole lot we can do
;-)
| >
| >
| >
Nov 21 '05 #11

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

Similar topics

3
by: ip4ram | last post by:
I am quite puzzled by the stack overflow which I am encountering.Here is the pseudocode //define stack structure //function operating on stack void my_stack_function( function parameters) {...
7
by: Aguilar, James | last post by:
Hello all, To begin, yes, this -is- a homework assignment. However, it is for my Algorithms class, and my instructor has given us explicit permission to use "expert" groups like newsgroups, so...
19
by: Jim | last post by:
I have spent the past few weeks designing a database for my company. The problem is I have started running into what I believe are stack overflow problems. There are two tab controls on the form...
4
by: Victor | last post by:
Hello, I've got a situation in which the number of (valid) recursive calls I make will cause stack overflow. I can use getrlimit (and setrlimit) to test (and set) my current stack size. ...
2
by: David W. Walker | last post by:
I am attempting to port a C code that runs OK on a number of Linux and Unix machines to Windows XP using Visual Studio C++. I have set the program up as a console application, but when I try to run...
3
by: tomb | last post by:
Please help! I have a handler in a class that handles when a column in a table is modified, as such: dtWhatif = dsOp.Tables("whatif") AddHandler dtWhatif.ColumnChanged, New...
2
by: Ali | last post by:
Hi, I got stack overflow errors while using an unmanaged dll from managed c# application. When i use editbin.exe to increase stack size of app , it works. Is there a way to increase stack size of...
6
by: Daz | last post by:
Hi everyone! It is indeed, once again time for me to ask another stupid question. I have been searching around on the net for quite a while, and can't find anything that explains 'exactly'...
7
by: amit.atray | last post by:
Environement : Sun OS + gnu tools + sun studio (dbx etc) having some Old C-Code (ansi + KR Style) and code inspection shows some big size variable (auto) allocated (on stack) say for ex. char...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.