Is there any function in VB, which is similar to Sleep(milliseconds); Method in c++
I want to suspend the execution without wasting processor time, in my VB program...

Thanks In Advance
Sunil

Re: Wanna Sleep! by Bob

Bob
Fri Apr 30 01:02:23 CDT 2004

=?Utf-8?B?U3VuaWw=?= wrote:
>
> Is there any function in VB, which is similar to Sleep(milliseconds); Method in c++?
> I want to suspend the execution without wasting processor time, in my VB program....
>

maybe something like this?

Public Declare Sub Sleep Lib "kernel32" (ByVal dwmilliseconds As Long)




Bob

Re: Wanna Sleep! by tgsunil

tgsunil
Fri Apr 30 01:41:03 CDT 2004

Oh my god, thats exactly what I tried. But no matter what delay in milliseconds you give, it hangs there forever....
Any idea why

Sunil

Re: Wanna Sleep! by Bob

Bob
Fri Apr 30 01:47:07 CDT 2004

=?Utf-8?B?U3VuaWw=?= wrote:
>
> Oh my god, thats exactly what I tried. But no matter what delay in milliseconds
> you give, it hangs there forever....
> Any idea why?
>


Nope. Something else is probably going on.
Perhaps something that you don't see the connection to.

Might help if you shared more about what you're trying to do
and what effects you're seeing.


Bob

Re: Wanna Sleep! by tgsunil

tgsunil
Fri Apr 30 02:11:04 CDT 2004

If you make a simple test app in vb6, and call Sleep API from that, (give argument as 10
You'll notice that the sleep funtion never returns... even after the specified timeout...

I created a new proj, added these extra code :

Private Declare Function Sleep Lib "kernel32" (ByVal dwMilliseconds As Long

Private Sub Form_Load(
Sleep 10
End Su

Thats it.

Sunil

Re: Wanna Sleep! by Bob

Bob
Fri Apr 30 02:24:54 CDT 2004

=?Utf-8?B?U3VuaWw=?= wrote:
>
> If you make a simple test app in vb6, and call Sleep API from that, (give argument as 10)
> You'll notice that the sleep funtion never returns... even after the specified timeout....
>
> I created a new proj, added these extra code :
>
> Private Declare Function Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
>
> Private Sub Form_Load()
> Sleep 100
> End Sub
>
> Thats it.


uh ... exactly what are you expecting to observe?

If you don't put anything else in that procedure, there's going to be
absolutely no effect when the sleep call returns. Try adding something
after it - anything, even a messagebox.


Bob

Re: Wanna Sleep! by Bob

Bob
Fri Apr 30 02:29:32 CDT 2004

=?Utf-8?B?U3VuaWw=?= wrote:
>
> If you make a simple test app in vb6, and call Sleep API from that, (give argument as 10)
> You'll notice that the sleep funtion never returns... even after the specified timeout....
>
> I created a new proj, added these extra code :
>
> Private Declare Function Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
>
> Private Sub Form_Load()
> Sleep 100
> End Sub
>

oops!
this _may_ be the problem:

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
^^^

That way works much better for me.
Guess I'd better not type API declares from memory any more.

Now you've got me curious why it does as you say - it seems to never return
and the visible manifestation is the form doesn't load (at least that's what
I just saw in the IDE)



Bob

Re: Wanna Sleep! by anonymous

anonymous
Fri Apr 30 03:21:03 CDT 2004

It's obviously the thing that occurs AFTER the Sleep call, duh...!
But I'm not susprised your program's hanging and crashing if you're trying to use CreateThread aswell.

Re: Wanna Sleep! by anonymous

anonymous
Fri Apr 30 03:21:04 CDT 2004

You typed it fine, he copied it down wrong.

Re: Wanna Sleep! by tgsunil

tgsunil
Fri Apr 30 03:41:02 CDT 2004

Thanks bob. I made it a Sub, now it works fine...


Re: Wanna Sleep! by erewhon

erewhon
Fri Apr 30 04:38:25 CDT 2004

On Fri, 30 Apr 2004 00:29:32 -0700, Bob O`Bob
<filterbob@yahoogroups.com> wrote:

<snip>

>
>oops!
>this _may_ be the problem:
>
>Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
> ^^^

No - that would not be a problem
The result of the Function would just be undefined
eg: whatever happened to be in EAX

>That way works much better for me.
>Guess I'd better not type API declares from memory any more.
>
>Now you've got me curious why it does as you say - it seems to never return
>and the visible manifestation is the form doesn't load (at least that's what
>I just saw in the IDE)

Ah - I know what happened

Private Declare Function Sleep Lib "kernel32" (ByVal dwMilliseconds As
Long)

That is the equivalent of:

Private Declare Function Sleep Lib "kernel32" (ByVal dwMilliseconds As
Long) As Variant '<--------

And that pushes an extra hidden parameter on the stack, for the
returned Variant

That address is going to be pretty large, the App will Sleep for quite
a long time - and then GPF