Sleep
-
Hi I just tried to call Sleep(1000) in a thread function But when i tried to Unit threadFun(LPVOID lparam) { while(1) { Sleep(1000); // When tried to give break point over here appliacation gets terminates ............ } } Can any one give me solution to this Thanks
-
Hi I just tried to call Sleep(1000) in a thread function But when i tried to Unit threadFun(LPVOID lparam) { while(1) { Sleep(1000); // When tried to give break point over here appliacation gets terminates ............ } } Can any one give me solution to this Thanks
VVVimal wrote:
Can any one give me solution to this
Remove the call to
Sleep()
. It's almost always unnecessary and usually indicates a design flaw."Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
VVVimal wrote:
Can any one give me solution to this
Remove the call to
Sleep()
. It's almost always unnecessary and usually indicates a design flaw."Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
But i need a Sleep() function over there. Because i need a function to be get called every 1000 milliseconds
VVVimal wrote:
Because i need a function to be get called every 1000 milliseconds
Then use
SetTimer(1000)
."Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
Hi I just tried to call Sleep(1000) in a thread function But when i tried to Unit threadFun(LPVOID lparam) { while(1) { Sleep(1000); // When tried to give break point over here appliacation gets terminates ............ } } Can any one give me solution to this Thanks
VVVimal wrote:
Unit threadFun(LPVOID lparam) { while(1) { Sleep(1000); // When tried to give break point over here appliacation gets terminates ............ } }
I don't see why should the application "terminate" with this piece of code. (It might have probably helped us if you had given the remaining code within the thread function to see if anything is wrong) With more than one thread running, may be the issue is somewhere else? Besides that, like David said, remove the unnecessary Sleep call and replace it with something that makes sense of some sort.
It is a crappy thing, but it's life -^ Carlo Pallini
-
But i need a Sleep() function over there. Because i need a function to be get called every 1000 milliseconds
Remember that Windows is not a real-time system, your function might or might not be called at every 1000 milliseconds, depending on what's happening on the OS.
This signature was proudly tested on animals.
-
VVVimal wrote:
Unit threadFun(LPVOID lparam) { while(1) { Sleep(1000); // When tried to give break point over here appliacation gets terminates ............ } }
I don't see why should the application "terminate" with this piece of code. (It might have probably helped us if you had given the remaining code within the thread function to see if anything is wrong) With more than one thread running, may be the issue is somewhere else? Besides that, like David said, remove the unnecessary Sleep call and replace it with something that makes sense of some sort.
It is a crappy thing, but it's life -^ Carlo Pallini
-
does the application terminate or does it hang? i would thing that statement would cause the app to hang... continuous loop with a defined wait time.. is that 1000 seconds or milliseconds it's library specific..??
David
David, you again replied to me instead of the OP. You should click reply on the specific message that you want to reply to.
It is a crappy thing, but it's life -^ Carlo Pallini
-
Hi I just tried to call Sleep(1000) in a thread function But when i tried to Unit threadFun(LPVOID lparam) { while(1) { Sleep(1000); // When tried to give break point over here appliacation gets terminates ............ } } Can any one give me solution to this Thanks
-
Hi I just tried to call Sleep(1000) in a thread function But when i tried to Unit threadFun(LPVOID lparam) { while(1) { Sleep(1000); // When tried to give break point over here appliacation gets terminates ............ } } Can any one give me solution to this Thanks
I use Sleep() all the time in threaded code, there's no reason it should cause the termination in and of itself. However, the thread code you show runs in the context of a larger program, notably the main thread which created the thread you show. What is that thread doing? If it exits, it will take the created thread down with it. Make sure the main code is waiting for this thread to terminate before it does.
-
Hi I just tried to call Sleep(1000) in a thread function But when i tried to Unit threadFun(LPVOID lparam) { while(1) { Sleep(1000); // When tried to give break point over here appliacation gets terminates ............ } } Can any one give me solution to this Thanks
VVVimal wrote:
When tried to give break point over here appliacation gets terminates
do you mean, it is getting terminated when you try to debug?
-------------------------------------------- Suggestion to the members: Please prefix your main thread subject with [SOLVED] if it is solved. thanks. chandu.
-
VVVimal wrote:
When tried to give break point over here appliacation gets terminates
do you mean, it is getting terminated when you try to debug?
-------------------------------------------- Suggestion to the members: Please prefix your main thread subject with [SOLVED] if it is solved. thanks. chandu.
-
I just added WatiForSingleObject(threadHandle,INFINITE) now working fine. Can any one tell why does it so
My answer above told you exactly why WaitForSingleObject() solved the problem However, the thread code you show runs in the context of a larger program, notably the main thread which created the thread you show. What is that thread doing? If it exits, it will take the created thread down with it.