简体   繁体   English

如何防止我的HTTP服务器“休眠”?

[英]How to prevent my HTTP server from “sleeping”?

I've written 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). 我编写了一个非常基本的基于HTTP的服务器程序,它在我的计算机后台运行,允许我从Android自动执行各种任务(通过Tasker中的HTTP请求)。 This all works fine (barring this problem ), except that after more than about 30 minutes of inactivity, the application ends up falling asleep, as though it's being shunted out of memory, and takes a good minute or so to wake up when it receives an HTTP request or when I try to restore the window and interact with the UI. 这一切都很好(除了这个问题 ),除了超过大约30分钟的不活动后,应用程序最终入睡,就好像它被分流内存一样,并且需要很长一段时间才能在收到时醒来HTTP请求或当我尝试恢复窗口并与UI交互时。

I'm using System.Net.HttpListener to implement the server (using asynchronous calls to BeginListen ). 我正在使用System.Net.HttpListener来实现服务器(使用对BeginListen异步调用)。 How should I go about keeping it on its toes? 我该如何保持它的脚趾?

Is it possible that your process memory is being swapped out to disk? 您的进程内存是否可能被换出到磁盘? Perhaps write a little monitor task that just pings it every 5 minutes? 也许写一个小监视器任务,每隔5分钟就会ping一次? Note that this could also be useful for making sure it's still running - it could email you if it's down, for example :) 请注意,这也可用于确保它仍在运行 - 如果它已关闭,它可以通过电子邮件发送给您,例如:)

What is your OS (Windows XP / Seven / Server 2008 ...) and distribution ? 什么是您的操作系统(Windows XP / Seven / Server 2008 ...)和发行版? (Home / Pro / SBS...) ? (Home / Pro / SBS ......)?

Try to give hight priority to your process (like realtime). 尽量优先考虑您的流程(如实时)。

You can also try to perform some task with your process every 10 minutes... 您还可以尝试每10分钟对您的流程执行一些任务...

也许你可以做另一个线程,并定期检查你的HttpListerner实例IsListening

Looks like the problem description is missing mentioning of the actual problem itself. 看起来问题描述缺少提及实际问题本身。 On windows applications do not go into sleep mode. 在Windows应用程序上不进入睡眠模式。 Inactive apps might be swapped, but it should not take very long time when it gets a request. 非活动应用程序可能会被交换,但在收到请求时不应该花费很长时间。 In .Net 2 I have noticed similar behavior due to garbage collection of the Listener Object itself or associated objects due to long inactivity. 在.Net 2中,由于长时间不活动导致监听器对象本身或关联对象的垃圾收集,我注意到了类似的行为。 Try to keep a static reference of the listener object.This might help. 尝试保持监听器对象的静态引用。这可能会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM