windows - Is there a way to sleep unless a message is received? -
I am working in a service whose main loop looks like this:
While start (FServer.ServerState = ssStarted) and (Self.Terminated = false) self.ServiceThread.ProcessRequests (False); ProcessFiles; Sleep (3000); End;
There is a lot like the process application.process message
. I can not pass it to true
because if I do this, no message is received from Windows, and process files will not run, and it must be run continuously to keep speed CPU usage low is.
It just works fine until I try to shut down the service from the Windows Service Management list. When I hit the stop, it sends a message and hopes that it gets almost instant feedback, and if it is between sleep commands, then Windows will give me an error which the service did not respond to stop command.
So what do I have to say "sleep for 3000 or until you get the message, whichever comes first." I'm sure there is an API for this, but I'm not sure what this is. Do anyone know
Use the timer to run the process file, instead of hacking it into the main application loop. Then the process files will go to the interval you want and the messages will be processed correctly, not taking a 100% CPU.
Comments
Post a Comment