electron定时任务,打印内存占用情况
// 监听更新
function winUpdate(){// 每次执行完后重新设置定时器try {// 获取当前时间并格式化为易读的字符串const now = new Date();const timeString = now.toLocaleString();console.log(`当前时间: ${timeString}`);// 记录内存使用情况(可选)const memoryUsage = process.memoryUsage();console.log(`内存使用: ${Math.round(memoryUsage.heapUsed / 1024 / 1024)} MB`);console.log('定时任务执行中...');}catch(error) {console.error('定时任务出错:', error);}finally {// 无论如何都继续下一次执行setTimeout(winUpdate, 1000);}
}
winUpdate()
长期稳定运行