-1

我在电脑上运行一个巨大的 Flash 应用程序。电脑一直开机,大约一周后 chrome 崩溃(内存泄漏 - 程序太大而无法重新编码)。有没有办法每天在指定时间自动重启它?

问候鲁本

4

2 回答 2

0

假设您使用的是 Windows,您可以使用 Windows 任务计划程序,并创建一个日常任务。您可以指定任务来运行程序或批处理脚本。

有关这方面的更多信息,请查看http://support.microsoft.com/kb/308569

在 Linux/Unix 下,您可以使用 cronjob。

编辑:如果您使用批处理脚本,您还可以测试,如果 chrome 已经在运行。同样,此解决方案仅适用于 Windows(实际上我仅使用 Win7 对其进行了测试)。要测试一个应用程序(本例中的记事本),您可以使用以下代码:

tasklist /nh /fi "imagename eq notepad.exe" | find /i "notepad.exe" >nul && (
    echo Windows Media Player is running
) || (
    echo Windows Media Player is not running
)
于 2012-05-03T10:30:31.340 回答
0

这可以通过Javascript来实现。

    <script>

    /*
    Uncomment below line to test this.
    alert('We reloaded!');
    */

    /* Configure when to reload. */
    specified_time = [22,30]; /* [hours, minutes] */


    is_time_to_reload = function(){
        var current_time = new Date();

        return (
            (current_time.getHours() >= specified_time[0]) &&
            (current_time.getMinutes() >= specified_time[1])
        );
    }

    /* We might have just reloaded. This will avoid
         reloading again until the time comes tomorrow */
    if(is_time_to_reload()){
        var not_reload_again_today = true;
        var last_day_reloaded = (new Date()).getDay();
    }

    check_refresh = function(){
        var current_time = new Date();

        if (is_time_to_reload()){
            if (not_reload_again_today &&
                    current_time.getDay() == last_day_reloaded){
                return;
            } else {
                window.location.reload();
            }
        }
    }

    /* check once a minute. */
    setInterval(check_refresh, 60 * 1000); 

    </script>

它也可以通过 HTML 来实现,但是您将无法控制重新加载时间。

    <head>
        <!-- refresh page every 86400 seconds. -->
        <meta http-equiv="refresh" content="86400" />
    </head>
于 2012-05-03T11:33:17.113 回答