?
Solved

The number of elements in my arraylist continues to grow even after it hits a breakpoint and is no longer running.

Posted on 2013-06-27
4
Medium Priority
?
292 Views
Last Modified: 2013-06-28
First of all I am not insane or stupid (at least I hope not) I have been using .net for a few years and this is the funkiest thing that I have ever seen.

The code snippet that I have embedded is only the portion of the actual class code that I believe is affected.  

The Left property of Expression should only return 13 items in the arraylist.  My problem is that it is returning 26.  I have placed a breakpoint in Public Function Simplify on line ES.Add(Left) and
have stepped through the code and everything works perfectly until it gets to
the return statement of the Property Left.  At this point Left.count automatically jumps to 26!  

Now the crazy part is that after it hits the breakpoint and the code is no longer executing I can place my cursor over the property Left in the line ES.Add(Left) then remove the cursor and if I place it back again the small message that appears over Left that shows how many element are contained in it starts to increment by 13.  If I look in the watch window it shows me that Left still has only 13 elements in it.

I am totally lost.  I not only want to fix the problem but I am also interested to know what the heck is going on.

please help....................pretty please.

Public Class Expression
    Private _Left As New ArrayList
    Private _Terms As ArrayList


    Public ReadOnly Property Left() As ArrayList
        Get
            For Each item As Term In _Terms
                If item.LeftSide Then
                    _Left.Add(item)
                Else
                    Exit For
                End If
            Next
            Return _Left
        End Get
    End Property


    Public Function Simplify() As ArrayList

        Dim ES As New ArrayList

        ES.Add(Left) 'array of arrays

     End Function
End Class

Open in new window

0
Comment
Question by:NevSoFly
  • 2
  • 2
4 Comments
 
LVL 40
ID: 39283570
In order to display the value of a property, the debugger must execute the code in the property. So when you put the cursor over the property in the code window, it is called, thus going through the loop that adds one item for each one in Terms.

The Watch window probably stays at 13 because it show the count for Terms. But the cursor in the code window being over Lets, it gets the result of the property running.
0
 

Author Comment

by:NevSoFly
ID: 39284388
I did notice after my original post that the additional items being added to the arraylist where just the original 13 items repeated over and over.

Also even though the Watch window continuously reports 13 items, if I repeatedly collapse and expanded the variable an additional copy of the 13 items would appear each time.

This seemed to cause an error at first (can't remember what it was) but the error no longer appears.  I am concerned that this could be an issue down the road.  Is this a bug with VS or am I missing something?  

Since this is not causing an error should I continue coding or attempt to solve the mystery?
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 2000 total points
ID: 39285209
Have you read my first answer? There is no mystery.

Putting the cursor over the Left method to retrieve its value forces the debugger to call the method. Since the method loop 13 times to add items, it increases the number of items by 13.

This is simply an indirect result of using the debugger. You will not encounter that when the application is running, except when you read the Left property.

There are 2 ways that would prevent the thing to happen. Instead of checking the array through the property, check it through the _Left variable. Doing so does not call the property and does not trigger the code.

The other one would be to prevent your loop from running when you are in the debugger with something like the following (not exactly sure of the syntax since I cannot check where I am now, but should be close):

If Not System.Diagnostics.Debugger.IsAttached Then
   'Your loop...
End if
Return _Left
0
 

Author Closing Comment

by:NevSoFly
ID: 39285284
Understood.  Thanks for clearing that up for me.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question