title: How to differentiate between user exiting chat and client in sleep mode?
body: <p>I have a chat client (C# WPF Application) and a chat service (C# Web Service)  which runs on a server. Since an application that gets killed by task manager or crashes cannot execute code I implemented my own way of letting the service know when a user goes offline, even if he crashes or kills the application:</p>
  
  <p>The client sends every 4 seconds (configurable) a "keep-me-alive" request, which when received by the server turns that user's "KeepAlive" bool property to true. The service has a timer and when it elpases after 10 seconds (configurable) it calls a method called "AutoKick", which checks every user's KeepAlive.</p>
  
  <p>If KeepAlive is false then it sets the user offline and kicks him out from all the chatrooms until he logs in again or sends a keep-me-alive request. If KeepAlive is true then nothing happens to the user but KeepAlive is set to false causing him to get kicked if no keep-alive requests are sent in the next 10 seconds.</p>
  
  <p>When the user closes the program manually it calls a method to tell the service to set him offline immediately and kick him. If the client crashes/is killed/loses internet connection then the AutoKick notices after 10-20 seconds and sets the user offline. So far everything works as planned.</p>
  
  <p>The only problem is that when the user turns on sleep-mode, or simply enters sleep mode after being away from the PC for too long, no keep-me-alive requests can be sent, because as far I know no code can be executed during sleep, this causes the user to get kicked and set offline.</p>
  
  <p>I don't want the user to be set to offline because he's away from PC, instead I simply want the "Status" property (enum) to be changed from "Online" to "Away".</p>
  
  <p>Is there any way to differentiate between sleep mode (not working as intended) and the rest of the causes for connection loss? I'm open for any ideas regarding changing the whole auto-kick thing, as I frankly have no idea how other chat applications handle this kind of thing.</p>