very nice & easy... thx for the tip
i have 1 question though ....
how do i re-run the thread ?
for eg. i have inserted execution of a batch file under the thread using :
Code:
Private Sub threadfunc()
While running
Shell("c:\mymusic\list.bat", AppWinStyle.Hide, True)
running = False
End While
End Sub
batch file takes abt few seconds to run & then i dump batch file's output into a text box on my form, it works fine for the first time but then when i try to run it for the second time it says :
"Thread is running or terminated; it cannot restart."
here's my full code if it helps, it simply lists the contents of directory & dumps it in a textbox, i know i can do this w/o a batch file, but i just wanted to test the "threading" stuff, & i knw it's a crappy one coz i'm just a beginner in vb .net ;-)
Code:
Imports System.IO
Public Class Form1
Dim t = New Threading.Thread(New Threading.ThreadStart(AddressOf threadfunc))
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim fiFile As New System.IO.FileInfo("c:\mymusic\list.bat")
fiFile.Delete()
Dim objStreamWriter As StreamWriter
objStreamWriter = New StreamWriter("c:\mymusic\list.bat", True)
objStreamWriter.WriteLine("c:")
objStreamWriter.WriteLine("cd\")
'objStreamWriter.WriteLine("cd windows")
objStreamWriter.WriteLine("dir /s > c:\mymusic\list.txt")
objStreamWriter.Close()
t.start()
PictureBox1.Visible = True
Me.Refresh()
TWAIT:
If running = False Then
Dim myOutput = New StreamReader("c:\mymusic\list.txt")
Dim sValues = myOutput.ReadToEnd
Me.rtb1.Text = sValues
Else
PictureBox1.Visible = True
Me.Refresh()
GoTo TWAIT
End If
PictureBox1.Visible = False
running = False
End Sub
Private running As Boolean = True
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PictureBox1.Visible = False
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
running = False
t.Abort()
End Sub
Private Sub threadfunc()
While running
Shell("c:\mymusic\list.bat", AppWinStyle.Hide, True)
running = False
End While
End Sub
End Class
picturebox? = i have inserted a animated gif that is displayed till the batch file is running in back ground