|
-
Dec 30th, 2018, 04:02 PM
#1
Thread Starter
Member
Backgroundworker problem
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
-
Dec 30th, 2018, 06:36 PM
#2
Re: Backgroundworker problem
 Originally Posted by Daveeed
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
A few notes:
1. If you provide the interface containing the controls being referred to it would be easier to try the code you provided.
2. Perhaps you should use the "With" statement when referring to "StartInfo".
3. Why are you using fully qualified references such as "System.IO.StreamWriter"? If you use the "Imports" statement that shouldn't be necessary.
As to your actual question:
https://stackoverflow.com/questions/...ss-to-complete
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|