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
272 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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

929 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now