Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I need to have an even6t that stops sleep but I don't know what, I sa3w that event keyDown don't stop sleeo, how can I do?

What I have tried:

I tried to evoid sleep but I need it
Posted
Updated 5-Feb-20 6:24am
v2

CEvent MFC class. CEvent::ResetEvent() puts a thread function into sleep state and CEvent::SetEvent() wakes up function.
CEvent::PulseEvent() sets event to avalable and then unavailable.

Microsoft documentation:

[^]
 
Share this answer
 
Comments
Member 14594285 5-Feb-20 12:08pm    
mmmm..I saw documentation but it isn't very clear, so in setEvent I can put keyDown event like event that wakes program? Help
steveb 5-Feb-20 12:14pm    
keyDown in MFC is CWnd::OnKeyDown() of WM_KEYDOWN message handler. Put your SetEvent call into that message handler
Member 14594285 6-Feb-20 2:53am    
How must I do? Can I see an example?
Yes, you definitely want to avoid calling Sleep because there is nothing I am aware of that will stop it - it can not be interrupted.

You are better off waiting for an event using the CEvent class as mentioned. You can then call WaitForSingleObject or WaitForMultipleObjects and let it handle the "sleeping" for you.
 
Share this answer
 
Comments
Member 14594285 6-Feb-20 2:54am    
How must I do? Can I see an example?
Rick York 6-Feb-20 11:19am    
steveb's comment above had the hint for you. To use WaitForSingleObject you must pass it an object to wait for. That can be any 'handle' object that can be signalled. In your case, you need to declare an event object (CEvent or similar) accessible to the class that receives the keyboard messages and set the event when a key is pressed.
Member 14594285 6-Feb-20 3:25am    
I wrote:

for (int i = 0; i <= 20; i++)

{
Sleep(100);
WaitForSingleObject(OnKeyDown, 100);
...



but I have errors
Member 14594285 6-Feb-20 12:04pm    
so CEvent a = OnKeyDown? I don't understand..sorry but it's the first time for me

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900