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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

706 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

19 Experts available now in Live!

Get 1:1 Help Now