Sleep() syntax
-
Monday, May 14, 2012 7:37 AMDoes anyone know what is the meaning of (Sleep(300), true) ??
ajaind
All Replies
-
Monday, May 14, 2012 7:43 AM
Hi,
Do you mean Thread.Sleep?
Suspends the executing thread for 300 milliseconds.
If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".
-
Monday, May 14, 2012 7:46 AM
Sleep function suspends the current thread for 300 ms. the ", true" part is some other code that isn't directly related to this function. Can you provide the full code line?
- Proposed As Answer by Alexander SunModerator Tuesday, May 15, 2012 6:47 AM
-
Monday, May 14, 2012 7:49 AM
it's part of the while construct in a do while loop.
do { ... } while (condition1 && condition2 && (Sleep(300), true))
ajaind
-
Monday, May 14, 2012 7:53 AM
Hi,
First thing syntactically its not correct (compile error)
do { ... } while (condition1 && condition2 && (Sleep(300, true))This seems Sleep is custom function, could be Sleep with time and bool value. If you provide what its been doing in Sleep function will be helpful.
If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".
- Edited by Kris444 Monday, May 14, 2012 7:53 AM
-
Monday, May 14, 2012 8:16 AM
Hi,
Rather than asking in a forum click on Sleep and use go to definition to see what is is really is (it will go either to its code or will show this is a .NET Framework function). When you end up with a .NET framework function you should then check the documentation at http://msdn.microsoft.com/en-us/library/gg145045 (.NET Framework Class Library). Once familiar with this process you shouldn't any more have to post to find what a function is...
Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".
-
Monday, May 14, 2012 6:52 PM
For “while (condition1 && condition2 && (Sleep(300), true))” I suggest the next equivalent:
while( condition1 &&
condition2 &&
( new Func< bool >( () =>
{
Thread.Sleep( 300 );
return true;
} )() ) );
Or create a new 'MySleep' function that sleeps and then always returns true:
while( condition1 && condition2 && MySleep( 300 ) );
- Edited by Viorel_MVP Monday, May 14, 2012 6:53 PM
-
Tuesday, May 15, 2012 1:20 AMSleep looks like a custom method, not really anything to do with Thread.Sleep unless it's been turned into it's own method which seems a bit extended to me.
If a post helps you in any way or solves your particular issue, please remember to use the Propose As Answer option or Vote As Helpful
Visit the Forum: TechLifeForum -
Tuesday, May 15, 2012 4:51 AM
I just realized this thread is in the wrong section. It should have been in the VC++ section.
The Sleep() method used is the one available in Windows API. It's not a custom method
ajaind
-
Tuesday, May 15, 2012 6:58 AM
I just realized this thread is in the wrong section. It should have been in the VC++ section.
The Sleep() method used is the one available in Windows API. It's not a custom method
ajaind
Then see the meaning of Comma operator: http://msdn.microsoft.com/en-us/library/zs06xbxh(v=vs.100).aspx.
-
Tuesday, May 15, 2012 11:32 AM
The return type of method 'Sleep' is 'void'. A 'while' construct expects a boolean expression to evaluate whether the loop should continue or not. Since the return type of Sleep is void, it does not satisfy the 'boolean expression' condition, and so cannot be used directly in the while loop as a condition. However, combining Sleep with a 'true' in a compound expression satisfies the condition, becasue the compound expression evaluates to 'true' after sleeping for a certain time.
Hope this answers the question.
- Marked As Answer by ajaind Tuesday, May 15, 2012 12:04 PM

