Pausing for an open file to be closed

J

jcrouse

This is sort of a revisited item from about two months ago (don't get
mad Cor) with additional code. I am creating a batch file called
CreateMameGames.bat. I am then running that batch file to create a text file
called MameGames.cfg. Later on in my code I parse through the file and pull
out information. This all worked great but the file is 25MB. In an attempt
to spped up the parsing I added code to take the MameGames.cfg file, open
it, read it a line at a time and if I need that line later, write it to
another text file called Games.cfg. The problem is that the creation on the
25MB file, MameGames.cfg doesn't complete before I declare it with a
streamreader of the slimming down of the file. I have even put in a timer to
pause 60 seconds, but no luck. The few times it has run it did great,
reducing the file to 700kb in size. What are some of my options here? I run
it as a process and thought the the process.wait for exit would do it, but
it doesn't. Here is my code:

Dim strInput As String = Application.StartupPath & "\CreateMameGamesCFG.bat"

MsgBox("Please be patient. This operation could take a minute or two to
complete.", MsgBoxStyle.Information, "CPViewer")

Me.Cursor = Cursors.WaitCursor

Dim p As New System.Diagnostics.ProcessStartInfo

p.CreateNoWindow = True

p.WindowStyle = ProcessWindowStyle.Hidden

p.FileName = strInput

p.UseShellExecute = True

System.Diagnostics.Process.Start(p)

Dim pr As System.Diagnostics.Process = System.Diagnostics.Process.Start(p)

pr.WaitForExit()

pr.Close()

pr.Dispose()

Me.Cursor = Cursors.Default

Start = Microsoft.VisualBasic.DateAndTime.Timer

Finish = Start + 60.0

Do While Microsoft.VisualBasic.DateAndTime.Timer < Finish

Loop

MsgBox("Your file has been created successfully.", MsgBoxStyle.Information,
"CPViewer")

Dim srMameGamesCFG As StreamReader = New
StreamReader(Application.StartupPath & "\mamegames.cfg")

Dim sw As StreamWriter = New StreamWriter(Application.StartupPath &
"\Games.cfg")

strLine = "1"

Do Until strLine Is Nothing

strLine = srMameGamesCFG.ReadLine()

If strLine Is Nothing Then

Exit Do

ElseIf strLine.StartsWith("game (") = True Then

sw.WriteLine(strLine)

ElseIf strLine.StartsWith(vbTab & "name ") = True Then

sw.WriteLine(strLine)

ElseIf strLine.StartsWith(vbTab & "description ") = True Then

sw.WriteLine(strLine)

ElseIf strLine.StartsWith(vbTab & "video ( screen") = True Then

sw.WriteLine(strLine)

ElseIf strLine.Equals(")") = True Then

sw.WriteLine(strLine)

End If

Loop

sw.Close()



Thanks,

John
 
J

jcrouse

Oh yeah, here is the line that it is erroring out on saying that the file is
already open:

Dim srMameGamesCFG As StreamReader = New
StreamReader(Application.StartupPath & "\mamegames.cfg")



Thanks,

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top