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
282 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

735 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