Post[Help]Thread.Sleep alternative[Solved]

Posts 1–15 of 22 · Page 1 of 2
[Help]Thread.Sleep alternative[Solved]
Hi.

as you know , sleep freeze everything in the application.


i need the same thing but not freezing everything.

because im making something for msn.

my code in timer1 is ( interval 2000 )
Code:
sendkeys.send(richtextbox1.text)
sendkeys.send(textbox2.text)
sleep(2000)
sendkeys.send(F8)
my code in timer2 is ( interval 350 )
Code:
Randomize()
TextBox2.Text = CStr(Int(Rnd() * 999))

the problem is after " sendkeys.send(richtextbox.text) " the whole application freeze for 2 sec ( 2000ms ) so my timer2 stop generating random number and it send over 2 time the same number

what can i do ??

thx
Quote Originally Posted by l4sth4ck3r View Post
Hi.

as you know , sleep freeze everything in the application.


i need the same thing but not freezing everything.

because im making something for msn.

my code in timer1 is ( interval 2000 )
Code:
sendkeys.send(richtextbox1.text)
sendkeys.send(textbox2.text)
sleep(2000)
sendkeys.send(F8)
my code in timer2 is ( interval 350 )
Code:
Randomize()
TextBox2.Text = CStr(Int(Rnd() * 999))

the problem is after " sendkeys.send(richtextbox.text) " the whole application freeze for 2 sec ( 2000ms ) so my timer2 stop generating random number and it send over 2 time the same number

what can i do ??

thx
First thing that I don't understand. Why are you using two timers, when you can do this just by using 1 ??

The easy solution would be to put this code before sending the keys:
Code:
Randomize()
TextBox2.Text = CStr(Int(Rnd() * 999))
Because Timer2 has nothing to do with sending, means the timer1 will send the keys of the text written in textbox2. So, its a better solution. Also put this code before sleep(2000):
Code:
Application.DoEvents()
This causes the application to perform events even if the program hangs !!

Nextgen1 wrote some piece of custom sleeping. If my method doesn't help you, you can ask him for that !!

Regards
ok thanks ill try this.

why 2 timer ? ANSWER : timer 1 is for sendkey at 2000ms i cant make it faster ( reliability )
timer 1 is generating new number each 350ms. i will have other timer that will use random number too but with different interval ( 7000 ) so i keep it a 350 so that way anything using it get new number .

anywya thx ill give you news about it.
ok so i tryed.
nothing change.

the sleep still freeze the whole app.

see the new project i amde just to try it

Code:
Imports System.Threading.Thread
Public Class Form1

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Randomize()
        TextBox1.Text = CStr(Int(Rnd() * 999))
        Application.DoEvents()
        Sleep(1000)
    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        Randomize()
        TextBox2.Text = CStr(Int(Rnd() * 99999))
    End Sub
End Class
NextGen1: OutSide Link Removed.

both timer set to 100 ms

still freeze whole app so the Random 2 sleep with the Random 1

yes for this one i could have used only 1 timer but my other project realy need more timer .
ok i found wht thing you was talking about
Code:
Private Sub Sleep(ByVal PauseTime As Double)

        Dim Tind As Int16
        For Tind = 1 To PauseTime / 50
            Threading.Thread.Sleep(50)
            Application.DoEvents()
        Next

    End Sub
dont seem to work.
So you got a interval of 2000 why do you then let it sleep again?

I don't get that part...
Quote Originally Posted by Blubb1337 View Post
So you got a interval of 2000 why do you then let it sleep again?

I don't get that part...


if i dont sleep it it keep sending it again and again and again and again non-stop = huge ressource or crash. so i need to pose it a bit then he restart himself after 2 second
My pc/program does not even crash with a interval of 50 without sleep....
Quote Originally Posted by Blubb1337 View Post
My pc/program does not even crash with a interval of 50 without sleep....
READ dude..

its for msn. typing too fast in msn = crash.

my brother have high-end computer fresh install and when he start the app after 2 minute msn crash.

not sur what his comp but i know :
processor intel I7
8Gb ram DDR3
2x 1TB hd.

i must say this app isnt typing in blocnote but in msn.. dont ask too much lol
Quote Originally Posted by l4sth4ck3r View Post
READ dude..

its for msn. typing too fast in msn = crash.

my brother have high-end computer fresh install and when he start the app after 2 minute msn crash.

not sur what his comp but i know :
processor intel I7
8Gb ram DDR3
2x 1TB hd.

i must say this app isnt typing in blocnote but in msn.. dont ask too much lol
Well, I tried it on msn too and it was working fine. nvm then...
Ya, works perfect for me too, may be you have an issue with your MSN !!


That's My code from the snippets from the snippets Vault and it works fine

what you have to do is use

Sleep(2000)

I have tested it, and so has a few others

@ Other stuff
Your New, So....

A. I Removed your outside link, Outside Links our not allowed without permission.

B. Watch the Double posts, use the Edit Button


Quote Originally Posted by NextGen1 View Post


That's My code from the snippets from the snippets Vault and it works fine

what you have to do is use

Sleep(2000)

I have tested it, and so has a few others

@ Other stuff
Your New, So....

A. I Removed your outside link, Outside Links our not allowed without permission.

B. Watch the Double posts, use the Edit Button



i tryed your snipet but didnt worked.
it was only sleeping 50ms and again for everything.

if you could make a little project that i can have a look and make some try ?
cant you just use Hibernate? lol
Sure, One Second I will upload it here in this post

Edit:

Attached, It is nothing more then a Button which will

set label1.text + 1 then sleep for 3 seconds then + 1 and sleep for 3 more seconds.

with application.doevents.


It is attached:
Here is Virus scan
http://www.virustotal.com/analisis/1...0a9-1269523087

TimesUp.rarattachment deleted · 3 downloads before removal
Posts 1–15 of 22 · Page 1 of 2
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?