Hello,
I am trying to have a sub repeat an action every so often (happens to be a random timing) and my program freezes when I try to sleep the thread. Below is a general structure of the sub the thread is executing.

Any possible solutions? I do NOT want to use the Timer control.

Private Sub DoStartBuying()
        If Me.InvokeRequired Then
            Dim args As Object() = {}
            Me.Invoke(New DoStartBuyingDelegate(AddressOf DoStartBuying), args)
        Else
            'Some variable declarations
            'Multiple controls being casted, for example:
            'Dim txtRefreshMin As TextBox
            'Dim txtRefreshMinC() As Control = tabAccount.TabPages(1).Controls.Find("txtRefreshMin" & intThreadID, True)
            'txtRefreshMin = DirectCast(txtRefreshMinC(0), TextBox)
            Do Until bolRunning(intThreadID - 1) = False
                'Executes some code here, including a web request
                Thread.Sleep(5000)
            Loop
        End If
    End Sub

Thanks

Recommended Answers

All 3 Replies

Member Avatar for iamthwee
Do Until bolRunning(intThreadID - 1) = False
                'Executes some code here, including a web request
                Thread.Sleep(5000)
            Loop

That will keep waiting five seconds until intTreadID-1 = False, How fast is the ThreadID changing.

ThreadID is a public variable that changes when the user hits the Stop button.

And that's what I had that froze me. Thanks for your effort though.

Overload resolution failed because no Public 'Add' is most specific for these arguments: 'Public Function Add(text As String) As System.Windows.Forms.ListViewItem.ListViewSubItem': Not most specific. 'Public Function Add(item As System.Windows.Forms.ListViewItem.ListViewSubItem) As System.Windows.Forms.ListViewItem.ListViewSubItem': Not most specific.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.