Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

Make a thread wait (sleep) for 1s

So i'm using a thread let's say to count up to 1000. after it gets to 1000 i want it to want it to wait 1s and continue.
I tried with Threading.Thread.Sleep(1000) but this command also make the gui unresponding...
Any better alternative?
I haven't worked with threads very much, but if I had to guess, I'd say you're making the GUI sleep instead of your worker thread.

Code
Dim myThread As Sytem.Threading.Thread
myThread.Sleep(1000)
(Nov 10, 2015 07:06 AM)Hawk HF Wrote:  I haven't worked with threads very much, but if I had to guess, I'd say you're making the GUI sleep instead of your worker thread.

Code
Dim myThread As Sytem.Threading.Thread
myThread.Sleep(1000)

I tried that. GUI is still not responding.
(Nov 10, 2015 07:09 AM)SIM-2362662 Wrote:  I tried that. GUI is still not responding.

It should not be since you have two separate threads.

Can you provide some code?
Yeah post some code so we can help.
Yea, we need some code to see what's wrong.
I hope you're not calling Thread.Sleep() from the main thread.

Code
'Dim t As New Thread(AddressOf CountUp)
't.Start()

Private Sub CountUp()
    For i As Integer = 0 To 1000
        Debug.WriteLine(i)
    Next

    Thread.Sleep(1000)
End Sub
(Nov 10, 2015 07:16 AM)Hawk HF Wrote:  It should not be since you have two separate threads.

Can you provide some code?

I managed to fix it . Apperantly the main ui freezed because i used a set.visibility before sleeep (wtf..)
I removed that line and now it works fine. I still can't understand why that line would create such a error .. Anyway thank you man.
(Nov 10, 2015 07:54 AM)SIM-2362662 Wrote:  I managed to fix it . Apperantly the main ui freezed because i used a set.visibility before sleeep (wtf..)
I removed that line and now it works fine. I still can't understand why that line would create such a error .. Anyway thank you man.

why would you do that?
there is no logic there.
(Nov 10, 2015 07:54 AM)SIM-2362662 Wrote:  I managed to fix it . Apperantly the main ui freezed because i used a set.visibility before sleeep (wtf..)
I removed that line and now it works fine. I still can't understand why that line would create such a error .. Anyway thank you man.

Post your code here so we can have a look. It's better for you to understand why a piece of code works than you to leave without the understanding.
Add a stopwatch, no CPU will usage will harm your computer or your computer fan starts making noise and your gui does respond.

Take care.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by bytespmApr 5, 2025 08:33 AM 10 450 Apr 5, 2025 08:33 AM
Last Post: Robert Rouge
[C#] by SteamMar 12, 2019 04:03 PM 6 408 Mar 12, 2019 04:03 PM
Last Post: Steam
[Java] by MohinderJan 31, 2017 08:26 AM 6 206 Jan 31, 2017 08:26 AM
Last Post: Mohinder