Hey everyone! I made a program, wich starts a console file, and run some commands in it, which takes a little time, app. 20-30 seconds, but I have the problem, that the "Succes" message is showed before the "It takes a little time.." message, so it means that the work finishes instantly, but in fact, the commands are running so far. In the "-rebuild" section it freezes 20 seconds, and than its closed, and I dont know, why it finishes instantly :( Thank you, heres my code:
Code:
 
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        BackgroundWorker1.RunWorkerAsync()
        ProgressBar1.MarqueeAnimationSpeed = 60
        ProgressBar1.Visible = True
        exi.Enabled = False
        Button2.Enabled = False
        MessageBox.Show("It takes a little time...!")

    End Sub
    Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
        Dim myprocess As New Process
        Dim StartInfo As New System.Diagnostics.ProcessStartInfo
        StartInfo.FileName = "imgc.exe" 
        StartInfo.RedirectStandardInput = True
        StartInfo.RedirectStandardOutput = True
        StartInfo.UseShellExecute = False 
        StartInfo.CreateNoWindow = True
        myprocess.StartInfo = StartInfo
        myprocess.Start()
        Dim SW As System.IO.StreamWriter = myprocess.StandardInput
        Dim SR As System.IO.StreamReader = myprocess.StandardOutput
        SW.WriteLine("-open ""gta3.img""") 
        SW.WriteLine("-import ""infernus.txd""")
        SW.WriteLine("-import ""infernus.dff""")
        SW.WriteLine("-rebuild")
        SW.WriteLine("-close")
        SW.WriteLine("-exit")
        SW.Close()
        SR.Close()
    End Sub

    Private Sub BackgroundWorker1_RunWorkerCompleted(sender As Object, e As RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
        ProgressBar1.Visible = False
        exi.Enabled = True
        Button2.Enabled = True
        MessageBox.Show("Success!")

    End Sub