Is pausing of the process needed here?

J

jcrouse

Here is my code:

Dim sw As StreamWriter = File.CreateText(Application.StartupPath
& "\mameversion.bat")

sw.WriteLine(lblMameExePath.Text & " -help >""" &
Application.StartupPath & "\mameversion.txt""")

sw.Close()

Dim p As New System.Diagnostics.ProcessStartInfo

p.WindowStyle = ProcessWindowStyle.Hidden

p.FileName = Application.StartupPath & "\mameversion.bat"

p.UseShellExecute = True

System.Diagnostics.Process.Start(p)

If File.Exists(Application.StartupPath & "\mameversion.txt")
Then

Dim sr As StreamReader = New
StreamReader(Application.StartupPath & "\mameversion.txt")

strLine = sr.ReadLine()

sr.Close()

lblMameVersion.Text = Mid(strLine, 11, 4)

frm1.dblMameVer =
System.Convert.ToDouble(lblMameVersion.Text)

lblMameVersion.Refresh()

End If



What is happening is that I am creating the batch file, then executing the
batch file to create the text file. I then look inside the text file to get
a version number of the program. If I execute the code fast the version
number never gets written into the label control. If I step through it in
the debugger, it works fine. I think a run-time speed the version is yet to
be found when I try to write it to the label control. Could I be correct
here? If so, how do I put a momentary pause in the code?

Thanks,
John
 
J

jcrouse

More......This code is executed on a button click event. If after executing
it, I execute it a second time, the label control populates properly.

Thanks,
John
 
G

Greg Burns

Why not skip creating and launching the batch file and just launch MAME
directly?

Dim p As New System.Diagnostics.ProcessStartInfo(lblMameExePath.Text,
" -help >""" & Application.StartupPath & "\mameversion.txt""")

p.WindowStyle = ProcessWindowStyle.Hidden
p.UseShellExecute = True
System.Diagnostics.Process.Start(p)

PS: mine was 0.81, what version are they upto nowadays? :)

Greg
 
G

Greg Burns

John, check this out:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim psi As New
System.Diagnostics.ProcessStartInfo(lblMameExePath.Text, " -help")

psi.UseShellExecute = False
psi.RedirectStandardOutput = True

Dim myProcess As New Process
myProcess = Process.Start(psi)
Dim strLine As String = myProcess.StandardOutput.ReadToEnd()
myProcess.WaitForExit()

txtMameVersion.Text = Mid(strLine, 11, 4)

End Sub

Greg
 
J

jcrouse

Well, here im my exact code, copy and pasted:

Dim psi As New
System.Diagnostics.ProcessStartInfo(lblMameExePath.Text & " -help")

psi.UseShellExecute = False

psi.RedirectStandardOutput = True

Dim myProcess As New Process

myProcess = Process.Start(psi)

Dim strline As String = myProcess.StandardOutput.ReadToEnd

myProcess.WaitForExit()

lblMameVersion.Text = Mid(strline, 11, 4)


When it gets to the line, myProcess = Process.Start(psi) it errors out
saying it can't find the file specified. When I throw a quickwatch on psi it
looks like this:

FileName "C:\Mame\mame.exe -help" String

This appears to be just what I want. Any idea why I get a file not specified
error?

Thanks,
John
 
G

Greg Burns

I think this line is incorrect:
Dim psi As New System.Diagnostics.ProcessStartInfo(lblMameExePath.Text &
" -help")

Try it like this (the command argument need to be the second parameter):
Dim psi As New System.Diagnostics.ProcessStartInfo(lblMameExePath.Text,
" -help")

I don't have my demo here at work, to compare the rest.

Greg
 
J

jcrouse

That did it. I was passing it as a string as opposed to two seperate
parametrers. Now, is there a way to hide the DOS box that pops up?

Thanks alot,
John
 
J

jcrouse

Well the problem seems to be this: the psi will take the windostyle
parameter but I need to apply it to myProcess and it won't accept it.

Any ideas,
John
 
J

jcrouse

On a somewhat similar note, here is another event I'm executing:

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


Dim p As New System.Diagnostics.ProcessStartInfo

p.WindowStyle = ProcessWindowStyle.Hidden

p.FileName = strInput

p.UseShellExecute = True

System.Diagnostics.Process.Start(p)

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


Any idea how I can pause it until the process is complete before displaying
the msgbox. This process takes about 30 seconds or so. It is a 26MB text
file that's being created.

Thanks,
John
 
J

jcrouse

Well, the dilemma seems to be this. I want to be able to hide the DOS box
AND pause the code until execution is complete. If I create a process, I can
"WaitforExit" but not hide the DOS box. If I create a
"System.Diagnostics.Process", I can hide the DOS box but can't pause until
the execution is complete. How can I have the best of both worls?

Thank you,
John
 
J

jcrouse

Well, the code has been resolved. I started another thread for hiding of the
DOS boxes.
 

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