How to prevent my HTTP server from sleeping?

I wrote a very basic HTTP-based server program that runs in the background on my computer to allow me to automate various tasks from my Android (via HTTP requests in Tasker). All this works fine (banning this problem ), except that after more than 30 minutes of inactivity, the application finishes falling asleep as if it were being shunted from memory and takes about a minute or so to wake up when it receives an HTTP request or when I am trying to restore a window and interact with the user interface.

I use System.Net.HttpListenerto implement the server (using asynchronous calls BeginListen). How should I keep it on my toes?

+3
source share
4 answers

Perhaps you could make another thread and periodically check the frequency of your instance of the HttpListerner Issled.

+1
source

Is it possible that your process memory is unloaded to disk? Perhaps write a small monitor task that just pings it every 5 minutes? Please note that this can also be useful in order to make sure that it is still running - it can send you an email if this happens, for example :)

+3
source

(Windows XP/Seven/Server 2008...) ? (/Pro/SBS...)?

(, ).

10 ...

+2

It seems that in the description of the problem there is no mention of the most actual problem. Windows applications do not go to sleep. Inactive applications can be replaced, but it does not take long when it receives a request. In .Net 2, I noticed this behavior due to a failure of the garbage of the recipient object itself or related objects due to prolonged inactivity. Try to keep a static link to the listener object. This can help.

+1
source

Source: https://habr.com/ru/post/1772338/


All Articles