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
279 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

808 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