これが現代の答えです
Public Sub makeUniqueForLargeFiles(ByVal strFileSource As String)
Using sr As New System.IO.StreamReader(strFileSource)
Dim changeFileName = reserveFileName(strFileSource, False, True)
Using sw As New System.IO.StreamWriter(reserveFileName(strFileSource, False, True), False, defaultEncoding)
sr.Peek()
Dim lines As New Generic.Dictionary(Of Integer, System.Collections.Generic.List(Of Long))
While sr.BaseStream.Position < sr.BaseStream.Length
Dim offset = sr.BaseStream.Position
Dim l As String = sr.ReadLine()
Dim nextOffset = sr.BaseStream.Position
Dim hash = l.GetHashCode
Do ' a trick to put the for each in a "nest" that we can exit from
If lines.ContainsKey(hash) Then
Using sr2 = New System.IO.StreamReader(strFileSource)
For Each offset1 In lines.Item(hash)
sr2.BaseStream.Position = offset1
Dim l2 = sr2.ReadLine
If l = l2 Then
Exit Do 'will sr2.dispose be called here?
End If
Next
End Using
Else
lines.Add(hash, New Generic.List(Of Long))
End If
lines.Item(hash).Add(offset)
sw.WriteLine(l)
Loop While False
sr.BaseStream.Position = nextOffset
End While
End Using
End Using
End Sub