Quantcast
Channel: Visual Studio General Questions forum
Viewing all articles
Browse latest Browse all 21115

Application/Debugger hangs when using function

$
0
0

Dear guys

I hope you can help with a new problem I discovered recently using Visual Basic 2008 with .NET 3.5 framework on a Windows 7 machine building x64 application: The application I build  hangs in two occasions:
-In the build/production version randomly when using the application
-When the debugging in VS2008 random and when using break statements/break button

When ‘hang’ occurs the application doesn’t react anymore until killed in task manager.

After some research I was able to pinpoint the problem to a very small part of the code: the part where the application reads a flat file (with a delimited separated table), where line by line the data is read and converted to a structured array. This converting is not been done directly in the loop that’s reading through the file but through a public function, so it can be reused through the application. If I put the code of the function directory inside the loop, the problem is solved for both cases, and the application doesn’t hang anymore. Only that isn't a solution as the function is called for over more then 100 places from within the application.

So it seems there is a difference in using code through a function or directly, although I can’t make up what the difference is and why it would hang. For testing I  isolated the code below from the rest of the application in a new VB2008 project, and the problem still occured. So the 'hang' should be reproducible.

I hope you can somehow help. 

Thanks in advance!

The code:
        Dim myReader As IO.StreamReader
        myReader = System.IO.File.OpenText("d:\act_2014-03-20.dat")
        Dim teller As Integer = 0
        While myReader.Peek() <> -1
            Dim record = myReader.ReadLine()
            Dim dbrecord_split = record.Split(";")
            teller += 1
            If teller > 2 Then
                Dim dbrecord = generate_dbrecord_act(dbrecord_split)
             End If
        End While
        myReader.Close()
        myReader.Dispose()

The function (when using this code directly in the while loop the problem doesn’t occur anymore):
    Public Function generate_dbrecord_act(ByVal dbrecord_split As Array) As structure_actrecords
        Dim dbrecord As structure_actrecords
        Dim dbi As Integer = 0

        dbrecord.index = Val(dbrecord_split(dbi)) : dbi += 1
        dbrecord.basic.treinnr_treinserie = dbrecord_split(dbi) : dbi += 1
        dbrecord.basic.treinnr = dbrecord_split(dbi) : dbi += 1
        dbrecord.basic.drp = dbrecord_split(dbi) : dbi += 1
        dbrecord.basic.drp_act = dbrecord_split(dbi) : dbi += 1
    End Function

The structure:
Structure structure_actrecords
 Dim index As Integer
 Dim basic As structure_actrecords_basis
    End Structure

Structure structure_actrecords_basis
       Dim treinnr As String
        Dim treinnr_treinserie As String
        Dim drp As String
        Dim drp_act As String
    End Structure

Hope somone can help.


Thanks in Advance!

Regards,

Paul Bruning
Developer Analysis software



Viewing all articles
Browse latest Browse all 21115

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>