Martin H

Martin H

  • NA
  • 3
  • 5.2k

File locked Exception handling

Aug 10 2010 12:05 PM
I have 2 applications:
The first displays a data group and pulls if from multiple locations to a central location.  As it does so it formats the data and updates a txt file.

The second is used in multiple locations and reads from that location then displays customized views from there.  When making these 2 applications I was lazy and put very little error handling in them.

My major concern id when the First app is building the files on random occasions one of the instances of the 2nd app will try and access the txt file and hit a debug/crash with "File in use" .

My question:
Is there a generic way to handle the exception and just retry again on the next interval timer?

Here is what I am trying now -

Try
        Dim i As Integer

 For i = 1 To 5

                Dim sr As New IO.StreamReader("C:\Program Files\Snapshot\bin\StatusData_" & i & ".txt")
                Dim tempArray()
                Dim r As Integer
                r = 1

                Do While Not sr.EndOfStream
                    tempArray = Split(sr.ReadLine, ",")
                    If tempArray(0) = "91" Then
                        If tempArray(5) = "5" Then
                            TextBox1.AppendText(Environment.NewLine & tempArray(1))
                            RedCount = r + 1
                        End If

                Loop
                sr.Close()
            Next
        Catch de As Exception

        End Try





Answers (1)