System.Windows.Forms.Application.DoEvents()
or if you are in a form's code, it is simply:
Application.DoEvents()
This blog is a depository for things I have found regarding VB.NET and C#.NET development (and other things I may need to remember). This blog is primarily for my own reference, but if the information I found is useful to others, then that is great. If others want to contribute with comments or other information, then that is great too.
System.Windows.Forms.Application.DoEvents()
Application.DoEvents()
Dim list() As String
Dim sep() As Char = {""c}
Try
Dim s As New FileClass
s.Open(TextBoxDataFile.Text)
Dim buffer As String = ""
Do
If Not s.GetNextLine(buffer) Then
Exit Do
End If
list = buffer.Split(sep)
If buffer = "*****StartOfData*****" Then
Dim startOfData As Integer = s.GetCurrentOffset()
PreprocessData(s)
s.SetCurrentOffset(startOfData)
ProcessData(s)
End If
Loop Until s.EOF()
s.Close()
Catch ex As Exception
Return False
End Try
Imports System.IO
Imports System.text
Public Class FileClass
Const BUFFER_SIZE As Integer = 1024
Private g_file As StreamReader = Nothing
Private g_line As Integer = 0
Private g_position As Integer = 0
Private g_buffer(BUFFER_SIZE) As Char
Private g_bufferSize As Integer = 0
Private g_offset As Integer = 0
Private g_eofFlag As Boolean = True
Private g_lineBuffer As New StringBuilder(BUFFER_SIZE)
Private g_bufferOffset As Integer = 0
Public Function Open(ByVal filename As String) As Boolean
If Not g_file Is Nothing Then Close()
g_file = New StreamReader(filename)
g_line = 0
g_position = 0
g_eofFlag = False
g_bufferSize = 0
g_bufferOffset = 0
LoadBuffer()
End Function
Public Function Close() As Boolean
g_file.Close()
g_file = Nothing
g_line = 0
g_position = 0
g_eofFlag = True
g_bufferSize = 0
Return True
End Function
Public Function GetCurrentOffset() As Integer
Return g_offset
End Function
Public Function SetCurrentOffset(ByVal offset As Integer) As Boolean
Dim pos As Long = g_file.BaseStream.Seek(offset, SeekOrigin.Begin)
g_file.DiscardBufferedData()
LoadBuffer()
Return offset = pos
End Function
Public Function GetNextLine(ByRef data As String) As Boolean
g_lineBuffer.Length = 0
Dim ch As Char
Dim flag As Boolean = False
While Not flag
ch = g_buffer(g_position)
If ch = vbCr Then
' do nothing - skip cr
ElseIf ch = vbLf Then
flag = True
Else
g_lineBuffer.Append(ch)
End If
g_position = g_position + 1
If g_position = g_bufferSize Then
If Not LoadBuffer() Then
Exit While
End If
End If
End While
If flag Then
g_offset = g_bufferOffset + g_position
data = g_lineBuffer.ToString
Return True
End If
Return False
End Function
Private Function LoadBuffer() As Boolean
g_bufferOffset = Convert.ToInt32(g_file.BaseStream.Position)
g_position = 0
g_bufferSize = g_file.Read(g_buffer, 0, BUFFER_SIZE)
If g_bufferSize = 0 Then
g_eofFlag = True
Return False
End If
Return True
End Function
Public Function EOF() As Boolean
Return g_eofFlag
End Function
End Class