By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,552 Members | 905 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,552 IT Pros & Developers. It's quick & easy.

Pausing for an open file to be closed

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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

"jcrouse" <me> wrote in message news:eG*************@TK2MSFTNGP12.phx.gbl...
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

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.