views:

79

answers:

3

I'm currently using VS2008 and VB.NET.

When I attempt to populate a Queue that has not been instantiated with objects, the program simply hangs without throwing an error.

I have run into this issue multiple times in different parts of the program in the past few days.

What could be the cause of this?

Here's the code:

Structure ConsoleBufferLine
    Public EntryDate As Date
    Public Text As String

    Public Sub New(ByVal textLine As String)
        Text = textLine
        EntryDate = DateTime.Now
    End Sub
End Structure

The code that causes a hang:

Private Buffer As Queue(Of ConsoleBufferLine)
Buffer.Enqueue(New ConsoleBufferLine("-"))

vs

Private Buffer As NEW Queue(Of ConsoleBufferLine)
Buffer.Enqueue(New ConsoleBufferLine("-"))

EDIT: When I make a new project and type in the following code, it also fails to throw an exception. However, when I put a try-catch around it, the exception is then caught.

Public Class Form1

  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim S As New SortedList(Of String, String)
    S.Add("lol", "value")
    S.Add("lol", "value")
  End Sub
End Class
+1  A: 

Without more details, it's impossible to answer the question. But if I had to take a guess, I would suspect some sort of infinite loop. Have you used the debugger to step through your code and see what it is doing?

R Samuel Klatchko
Yes I've stepped through the code. When It gets to the Enqueue line where it instantiates a ConsoleBufferLine, it gets through the contructor OK, but when it backs out to do the actual Enqueue, then it hangs by showing the form window and not allowing anything. Attempting to step beyond that Enqueue is not possible because it simply hangs.
hamlin11
+1  A: 

I'm not sure why Visual Studio is hanging on the first sample code but there is definitely a bug in the usage.

Private Buffer As Queue(Of ConsoleBufferLine)
Buffer.Enqueue(New ConsoleBufferLine("-"))

In the above sample, you are declaring a reference Queue but not creating an instance of it. The value of Buffer will be Nothing so the call to Enqueue will cause a NullReferenceException to be thrown. The second example work because the extra New keyword causes an instance of the queue to be created.

What could be happening here is that there is a problem bringing up the Exception Assistant for this particular scenario. It should display if the first code sample is run and there could be another side issue which is giving it a problem displaying.

JaredPar
Any ideas on figuring what what is going on with the problem bringing up the Exception Assistant?
hamlin11
+2  A: 

The Visual Basic 2008 debugger does not appear to handle exceptions that are thrown during the "Handles MyBase.Load" event.

Such as this code:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'All code in here that throws exceptions will not throw an exception
    Throw New Exception("FFF")      'This will not be handled by VS debugger.
End Sub

There are two ways around this. Change the "Handles MyBase.Load" to "Handles MyBase.Shown". The second way would be to just program it to where stuff doesn't get initialized in the .load area.

CowKingDeluxe