
Originally Posted by
dunfiddlin
Sorry, I misread you code and didn't spot the dowork Sub tucked in at the bottom. The delay is caused by your sleep on the main thread which stops all thread activity before the start message has been transmitted. If you're going to sleep the main thread there's really no point in putting the browser navigate on another thread anyway. The whole point of threading is to keep the UI active!
Is there any way to start a thread, wait a second, and then start another thread? or is there some setting which affects how sleep works?
I have this multithread loop in one of my applications. In this application there is not pause between the thread starts. After the button click event is done it starts all 5 threads at the same time yet on a new application one starts then after 2 seconds another starts.
Code:
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim testthread As New System.Threading.Thread(AddressOf Module1.loop3)
Dim testthread1 As New System.Threading.Thread(AddressOf Module1.loop3)
Dim testthread2 As New System.Threading.Thread(AddressOf Module1.loop3)
Dim testthread3 As New System.Threading.Thread(AddressOf Module1.loop3)
Dim testthread4 As New System.Threading.Thread(AddressOf Module1.loop3)
testthread.Start(1)
System.Threading.Thread.Sleep(2000)
testthread1.Start(2)
System.Threading.Thread.Sleep(2000)
testthread2.Start(3)
System.Threading.Thread.Sleep(2000)
testthread3.Start(4)
System.Threading.Thread.Sleep(2000)
testthread4.Start(5)
System.Threading.Thread.Sleep(2000)
Call Module1.loop3(6)
End Sub
Code:
Public Sub loop3(ByVal column As Integer)
System.Threading.Thread.Sleep(2000)
If xl.visible <> True Then
xl.visible = True
End If
Try
If Not xl.activeworkbook.name = "Spenddown IN Mdcd.xlsm" Then
xl.workbooks.open("C:\Documents and Settings\BMcGuir1\Desktop\Test\spenddown in mdcd.xlsm")
GoTo done
End If
Catch
xl.workbooks.open("C:\Documents and Settings\BMcGuir1\Desktop\Test\spenddown in mdcd.xlsm")
End Try
done:
Dim y As Long
For y = 1 To 100
xl.activeworkbook.sheets("sheet1").cells(y, column).value = y
System.Threading.Thread.Sleep(100)
Next
'MsgBox("done")
End Sub
How some the sleep(2000) works on one application but not another?