INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Multiple process execution for program

Multiple process execution for program

(OP)
I am working on a vb .net application to run a dos based executable that emulates old arcade systems.

The problem I am having is that i can execute one process only at a time. When I exit that process I can then execute another one. I want to be able to execute multiple processes of the same executable.

my code is below:

CODE -->

Dim tiimgtargs, tiimgresult As String
        If chksbridge.Checked = True Then
            If System.IO.File.Exists(txtTIMGdir.Text & "\tiimagetool.exe") Then


                tiimgresult = "TIIMAGETOOL Executubale File Found!"
                Dim TIITProcess As New ProcessStartInfo
                tiimgtargs = "-jar tiimagetool.jar BRIDGE " & cmbsbridge.SelectedItem.ToString & " 10000"
                TIITProcess.FileName = "java"
                TIITProcess.Arguments = tiimgtargs
                TIITProcess.WorkingDirectory = txtTIMGdir.Text
                Process.Start(TIITProcess)
            Else
                tiimgresult = "FAILURE : TIIMAGETOOL File Not Found!"
            End If

        End If

        Static start_time As DateTime
        Static stop_time As DateTime
        Dim elapsed_time As TimeSpan
        Dim mameresult As String
        Dim myProcess As New Process
        Dim myProcessStartInfo As New ProcessStartInfo(txtMessDir.Text & "\" & txtMExecut.Text)
        myProcessStartInfo.WorkingDirectory = txtMessDir.Text
        myProcessStartInfo.Arguments = GV.rom & GV.joy & GV.cartconfig & GV.slot2 & GV.slot3 & GV.slot4 & GV.slot5 & GV.slot6 & GV.slot7 & GV.slot8
        myProcessStartInfo.UseShellExecute = False
        myProcessStartInfo.RedirectStandardError = True
        myProcess.StartInfo = myProcessStartInfo
        start_time = Now
        If System.IO.File.Exists(txtMessDir.Text & "\" & txtMExecut.Text) Then
            mameresult = "MAME Executable File Found!"
        Else
            mameresult = "MAME Executable File NOT Found!"
        End If

        myProcess.Start() 

RE: Multiple process execution for program

You don't show how you call the above code - but there should not be any reason for you not to be able to do what you want.

For example if the activation code (above) is in a sub or function and you have a button on a form to call that routine, then everytime you press the button a new instance of your dos program should be started.

RE: Multiple process execution for program

(OP)
I was launching the above code with a button on the main form.

I tried to implement my code via a module but it still freezes the form until the process is closed.

I was able to successfully implement separate threads by the below code additions. I just copied my entire code that references various controls. I am using various logic to determine correct arguments to be passed to my executable.

adding the below to the main form at the beginning:

CODE -->

Imports System.Threading 

CODE -->

Private trd As Thread 

CODE -->

Private Sub ThreadTask()
        Static start_time As DateTime
        Static stop_time As DateTime
        Dim elapsed_time As TimeSpan
        Dim mameresult As String
        Dim myProcess As New Process
        Dim myProcessStartInfo As New ProcessStartInfo(txtMessDir.Text & "\" & txtMExecut.Text)
        myProcessStartInfo.WorkingDirectory = txtMessDir.Text
        myProcessStartInfo.Arguments = GV.rom & GV.joy & GV.cartconfig & GV.slot2 & GV.slot3 & GV.slot4 & GV.slot5 & GV.slot6 & GV.slot7 & GV.slot8
        myProcessStartInfo.UseShellExecute = False
        myProcessStartInfo.RedirectStandardError = True
        myProcess.StartInfo = myProcessStartInfo
        start_time = Now
        If System.IO.File.Exists(txtMessDir.Text & "\" & txtMExecut.Text) Then
            mameresult = "MAME Executable File Found!"
        Else
            mameresult = "MAME Executable File NOT Found!"
        End If
        myProcess.Start()

        Dim myStreamReader As StreamReader = myProcess.StandardError
        ' Read the standard output of the spawned process.
        Dim myString As String = myStreamReader.ReadToEnd()
        myProcess.Close()
        stop_time = Now
        elapsed_time = stop_time.Subtract(start_time)

        'Execution Log 
        Dim sw As StreamWriter
        Dim fs As FileStream = Nothing
        Dim logfile As String = txtlfdir.Text & GV.logfile
        'MsgBox(logfile)
        If (Not File.Exists(logfile)) Then
            Try
                fs = File.Create(logfile)
                sw = File.AppendText(logfile)
                sw.WriteLine("-----------------START OF LOG ENTRY-----------------")
                sw.WriteLine("OOEYGUI LAUNCH AT " & start_time)
                If chksbridge.Checked = True Then
                    sw.WriteLine("TIIMAGETOOL Selected...")
                    sw.WriteLine("TIIMAGETOOL Command > " & "java " & " tiimage arguments here")
                    sw.WriteLine("TIIMAGETOOL Status > " & " tiimage result here")
                End If
                sw.WriteLine("MAME Status > " & mameresult)
                sw.WriteLine("command line:")
                sw.WriteLine(txtMessDir.Text & "\" & txtMExecut.Text & " " & myProcessStartInfo.Arguments)
                sw.WriteLine("exited: " & stop_time)
                sw.WriteLine(myString)
                sw.WriteLine("Application Run Time in seconds:" & elapsed_time.TotalSeconds.ToString("0.000000"))
                sw.WriteLine("-----------------END OF LOG ENTRY-----------------")
                sw.WriteLine(" ")
                sw.Close()

            Catch ex As Exception
                MsgBox("Error Creating Log File")
            End Try

        Else

            sw = File.AppendText(logfile)
            sw.WriteLine("-----------------START OF LOG ENTRY-----------------")
            sw.WriteLine("OOEYGUI LAUNCH AT " & start_time)
            If chksbridge.Checked = True Then
                sw.WriteLine("TIIMAGETOOL Selected...")
                sw.WriteLine("TIIMAGETOOL Command > " & "java " & " tiimage arguments here")
                sw.WriteLine("TIIMAGETOOL Status > " & " tiimage result here")
            End If
            sw.WriteLine("MAME Status > " & mameresult)
            sw.WriteLine("command line:")
            sw.WriteLine(txtMessDir.Text & "\" & txtMExecut.Text & " " & myProcessStartInfo.Arguments)
            sw.WriteLine("exited: " & stop_time)
            sw.WriteLine(myString)
            sw.WriteLine("Application Run Time in seconds:" & elapsed_time.TotalSeconds.ToString("0.000000"))
            sw.WriteLine("-----------------END OF LOG ENTRY-----------------")
            sw.WriteLine(" ")
            sw.Close()

            sw.Close()
        End If
        If myString.Replace(Environment.NewLine, "").Replace(vbTab, "").Replace(" ", "") <> "" Then
            MsgBox("Launch Error...Please view log!")

        End If

    End Sub 

Added the below code to the Button on form1:

CODE -->

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim sp, hdi, fdi, ci, tsl2, tsl3, tsl4, tsl5, tsl6, tsl7, tsl8, hds1, hds2, hds3 As String
        Dim HDIDE, HDIDE2, HDMFM, HDMFM2, HDCDROM, HDTYPE As Integer


        sp = " "

        PopSlots.Launch()

        HDIDE = DirectCast(cmbslot6.SelectedItem, MyListItem).ItemData
        HDIDE2 = DirectCast(cmbslot7.SelectedItem, MyListItem).ItemData
        HDMFM = DirectCast(cmbslot7.SelectedItem, MyListItem).ItemData
        HDMFM2 = DirectCast(cmbslot8.SelectedItem, MyListItem).ItemData


        If HDMFM = 14 Then

            If Len(txthd1.Text) > 8 Then
                If File.Exists(txthd1.Text) Then
                    HDTYPE = DirectCast(cmbhdtype1.SelectedItem, MyListItem).ItemData
                    Select Case HDTYPE
                        Case 1
                            GV.slot7 = GV.slot7 & " -peb:slot7:hfdc:h1 generic -hard1 " & txthd1.Text
                        Case 2
                            GV.slot7 = GV.slot7 & " -peb:slot7:hfdc:h1 st215 -hard1 " & txthd1.Text
                        Case 3
                            GV.slot7 = GV.slot7 & " -peb:slot7:hfdc:h1 st225 -hard1 " & txthd1.Text
                        Case 4
                            GV.slot7 = GV.slot7 & " -peb:slot7:hfdc:h1 st251 -hard1 " & txthd1.Text
                    End Select
                Else
                    GV.slot7 = GV.slot7 & " -peb:slot7:hfdc:h1 generic"
                End If
            Else
                GV.slot7 = GV.slot7 & " -peb:slot7:hfdc:h1 generic"
            End If


            If Len(txthd2.Text) > 8 Then

                If File.Exists(txthd2.Text) Then
                    HDTYPE = DirectCast(cmbhdtype2.SelectedItem, MyListItem).ItemData
                    Select Case HDTYPE
                        Case 1
                            GV.slot7 = GV.slot7 & " -peb:slot7:hfdc:h2 generic -hard2 " & txthd2.Text
                        Case 2
                            GV.slot7 = GV.slot7 & " -peb:slot7:hfdc:h2 st215 -hard2 " & txthd2.Text
                        Case 3
                            GV.slot7 = GV.slot7 & " -peb:slot7:hfdc:h2 st225 -hard2 " & txthd2.Text
                        Case 4
                            GV.slot7 = GV.slot7 & " -peb:slot7:hfdc:h2 st251 -hard2 " & txthd2.Text
                    End Select
                Else
                    GV.slot7 = GV.slot7 & " -peb:slot7:hfdc:h2 generic"
                End If
            Else
                GV.slot7 = GV.slot7 & " -peb:slot7:hfdc:h2 generic"
            End If

            If Len(txthd3.Text) > 8 Then

                If File.Exists(txthd3.Text) Then
                    HDTYPE = DirectCast(cmbhdtype3.SelectedItem, MyListItem).ItemData
                    Select Case HDTYPE
                        Case 1
                            GV.slot7 = GV.slot7 & " -peb:slot7:hfdc:h3 generic -hard3 " & txthd3.Text
                        Case 2
                            GV.slot7 = GV.slot7 & " -peb:slot7:hfdc:h3 st215 -hard3 " & txthd3.Text
                        Case 3
                            GV.slot7 = GV.slot7 & " -peb:slot7:hfdc:h3 st225 -hard3 " & txthd3.Text
                        Case 4
                            GV.slot7 = GV.slot7 & " -peb:slot7:hfdc:h3 st251 -hard3 " & txthd3.Text
                    End Select
                Else
                    GV.slot7 = GV.slot7 & " -peb:slot7:hfdc:h3 generic"
                End If
            Else
                GV.slot7 = GV.slot7 & " -peb:slot7:hfdc:h3 generic"
            End If
            GV.slot7 = GV.slot7 & " -peb:slot7:hfdc:h1 generic -peb:slot7:hfdc:h2 generic -peb:slot7:hfdc:h3 generic"
        End If



        If HDMFM2 = 14 Then

            If Len(txthd1.Text) > 8 Then
                If File.Exists(txthd1.Text) Then
                    HDTYPE = DirectCast(cmbhdtype1.SelectedItem, MyListItem).ItemData
                    'MsgBox(HDTYPE.ToString)
                    Select Case HDTYPE
                        Case 1
                            GV.slot8 = GV.slot8 & " -peb:slot8:hfdc:h1 generic -hard1 " & txthd1.Text
                        Case 2
                            GV.slot8 = GV.slot8 & " -peb:slot8:hfdc:h1 st215 -hard1 " & txthd1.Text
                        Case 3
                            GV.slot8 = GV.slot8 & " -peb:slot8:hfdc:h1 st225 -hard1 " & txthd1.Text
                        Case 4
                            GV.slot8 = GV.slot8 & " -peb:slot8:hfdc:h1 st251 -hard1 " & txthd1.Text
                    End Select
                Else
                    GV.slot8 = GV.slot8 & " -peb:slot8:hfdc:h1 generic"
                End If
            Else
                GV.slot8 = GV.slot8 & " -peb:slot8:hfdc:h1 generic"
            End If


            If Len(txthd2.Text) > 8 Then

                If File.Exists(txthd2.Text) Then
                    HDTYPE = DirectCast(cmbhdtype2.SelectedItem, MyListItem).ItemData
                    Select Case HDTYPE
                        Case 1
                            GV.slot8 = GV.slot8 & " -peb:slot8:hfdc:h2 generic -hard2 " & txthd2.Text
                        Case 2
                            GV.slot8 = GV.slot8 & " -peb:slot8:hfdc:h2 st215 -hard2 " & txthd2.Text
                        Case 3
                            GV.slot8 = GV.slot8 & " -peb:slot8:hfdc:h2 st225 -hard2 " & txthd2.Text
                        Case 4
                            GV.slot8 = GV.slot8 & " -peb:slot8:hfdc:h2 st251 -hard2 " & txthd2.Text
                    End Select
                Else
                    GV.slot8 = GV.slot8 & " -peb:slot8:hfdc:h2 generic"
                End If
            Else
                GV.slot8 = GV.slot8 & " -peb:slot8:hfdc:h2 generic"
            End If

            If Len(txthd3.Text) > 8 Then
                If File.Exists(txthd3.Text) Then
                    HDTYPE = DirectCast(cmbhdtype3.SelectedItem, MyListItem).ItemData
                    Select Case HDTYPE
                        Case 1
                            GV.slot8 = GV.slot8 & " -peb:slot8:hfdc:h3 generic -hard3 " & txthd3.Text
                        Case 2
                            GV.slot8 = GV.slot8 & " -peb:slot8:hfdc:h3 st215 -hard3 " & txthd3.Text
                        Case 3
                            GV.slot8 = GV.slot8 & " -peb:slot8:hfdc:h3 st225 -hard3 " & txthd3.Text
                        Case 4
                            GV.slot8 = GV.slot8 & " -peb:slot8:hfdc:h3 st251 -hard3 " & txthd3.Text
                    End Select
                Else
                    GV.slot8 = GV.slot8 & " -peb:slot8:hfdc:h3 generic"
                End If
            Else
                GV.slot8 = GV.slot8 & " -peb:slot8:hfdc:h3 generic"
            End If
        Else

            GV.slot8 = GV.slot8 & " -peb:slot8:hfdc:h1 generic -peb:slot8:hfdc:h2 generic -peb:slot8:hfdc:h3 generic"
        End If

        If cmbROM.SelectedIndex <> 5 Then

            If cmbCartconfig.SelectedIndex = 0 Or cmbCartconfig.SelectedIndex = 2 Then
                GV.cartconfig = GV.cartconfig & sp & "-cart1 " & txtcart1.Text
            End If
            If cmbCartconfig.SelectedIndex = 1 Then
                If Len(txtcart1.Text) > 8 Then
                    If File.Exists(txtcart1.Text) Then
                        GV.cartconfig = GV.cartconfig & sp & "-cart1 " & txtcart1.Text
                    End If
                Else
                End If
                If Len(txtcart2.Text) > 8 Then
                    If File.Exists(txtcart2.Text) Then
                        GV.cartconfig = GV.cartconfig & sp & "-cart2 " & txtcart2.Text
                    End If
                Else
                End If
                If Len(txtcart3.Text) > 8 Then
                    If File.Exists(txtcart3.Text) Then
                        GV.cartconfig = GV.cartconfig & sp & "-cart3 " & txtcart3.Text
                    End If
                Else

                End If
                If Len(txtcart4.Text) > 8 Then
                    If File.Exists(txtcart4.Text) Then
                        GV.cartconfig = GV.cartconfig & sp & "-cart4 " & txtcart4.Text
                    End If
                Else
                End If
            End If
        Else
            GV.cartconfig = ""
        End If
        Dim tiimgtargs, tiimgresult As String

        If chksbridge.Checked = True Then
            If System.IO.File.Exists(txtTIMGdir.Text & "\tiimagetool.exe") Then


                tiimgresult = "TIIMAGETOOL Executubale File Found!"
                Dim TIITProcess As New ProcessStartInfo
                tiimgtargs = "-jar tiimagetool.jar BRIDGE " & cmbsbridge.SelectedItem.ToString & " 10000"
                TIITProcess.FileName = "java"
                TIITProcess.Arguments = tiimgtargs
                TIITProcess.WorkingDirectory = txtTIMGdir.Text
                Process.Start(TIITProcess)
            Else
                tiimgresult = "FAILURE : TIIMAGETOOL File Not Found!"
            End If

        End If

        

        trd = New Thread(AddressOf ThreadTask)
        trd.IsBackground = True

        trd.Start()


    End Sub 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close