sleep

Android: Change delay before the phone is put to sleep while my app is running

做~自己de王妃 提交于 2019-12-12 01:16:52
问题 This question sounds so easy I can't believe I can't find information on it (maybe I have the wrong key words in mind...) I'm looking for a way to change the delay before the phone is put to sleep when my app is running. I was using wake locks until now to prevent my app from being closed to frequently (its and opengl app and the loading time is a killer specially on slow phones). I don't like the idea of indefinitely leaving the phone on (mainly because it empties the battery fast to have a

Nodejs child_process spawn calling python script with sleep

烂漫一生 提交于 2019-12-12 00:26:47
问题 I'm testing on nodejs child_process module to read the stdout from my python script. However, I noticed when my python emit message between every second. The nodejs callback can only collect the stdout at the end of the python script ends. Python Script import time for i in range(0,5): ····print i ····time.sleep(0.5) and the nodejs script is var cp = require('child_process'); var spw = cp.spawn('python', ['tql.py']), str = ""; spw.stdout.on('data', function (data) { str+= data; console.log

How can I write a function that takes X amount of seconds?

偶尔善良 提交于 2019-12-11 21:02:42
问题 I want to write a javascript function that takes very close to 5 seconds to run. How can I make that guarantee? I have tried function wait(numSeconds) { var end = new Date().getMilliseconds() + numSeconds * 1000; while (new Date().getMilliseconds() <= end) {} } but this just crashes the page. 回答1: you can use: var t = setTimeout(function(){alert('done')},5000); 回答2: You cannot freeze the page without freezing the page. You're trying to write a function that runs for 5 seconds straight.

File Cleaning Service

北城余情 提交于 2019-12-11 19:57:51
问题 As a requirement in Android OS phone, I am developing an app which will clean up a particular folder in a specified interval of time, say every 30 minutes. I can run a service and clean up the folder every 30 mins. I have few questions over this, 1.Service has onStartCommand, which will be executed when the service starts, can I call a function here which has a Handler which runs every 30 minutes? Example public int onStartCommand(Intent intent, int flags, int startId){ cleanUpData(); return

Does msleep() give cycles to other threads?

﹥>﹥吖頭↗ 提交于 2019-12-11 19:39:10
问题 In a multi threaded app, is while (result->Status == Result::InProgress) Sleep(50); //process results better than while (result->Status == Result::InProgress); //process results ? By that, I'm asking will the first method be polite to other threads while waiting for results rather than spinning constantly? The operation I'm waiting for usually takes about 1-2 seconds and is on a different thread. 回答1: It's better, but not by much. As long as result->Status is not volatile , the compiler is

SetSuspendState() API never returns in Win8

梦想的初衷 提交于 2019-12-11 19:20:32
问题 Let me explain my problem statement: In my VC++ project I want to insert a logic to send my system (Windows 8) to Sleep state programatically & resume back. I'm doing it like this (Copying the code snippet) :: int wait = 100; LARGE_INTEGER WaitTime; WaitTime.QuadPart = wait; WaitTime.QuadPart *= -10000000; HANDLE hTimer = CreateWaitableTimer(NULL, FALSE, NULL); if(0 == SetWaitableTimer(hTimer, &WaitTime, 0, NULL, NULL, TRUE)) { res = false; return res; } if(0 == SetSuspendState(FALSE, FALSE,

_sleep() is not working in C++

眉间皱痕 提交于 2019-12-11 18:08:36
问题 I was trying to write simple code, but whenever I call the function _sleep() it doesn't work. I have tried it in two different projects now, and every time I use it, it gives me an error that says:1 '_sleep': This function or variable has been superseded by newer library or operating system functionality. Consider using Sleep instead. See online help for details. I tried so much other stuff like Sleep() , sleep() and just a bunch of other random junk that didn't end up working. If there

java - thread.sleep() within SwingWorker

元气小坏坏 提交于 2019-12-11 17:34:21
问题 I am just wondering if the following code is correct. I have a SwingWorker that does something, sleeps, does something else and updates GUI. Is it okay to use Thread.sleep inside SwingWorker? class MySwingy extends SwingWorker<Void, Void> { @Override public Void doInBackground() { //Do Something try { Thread.sleep(200); } catch (Exception ex) { } //Do Something } @Override public void done() { //Update GUI } } 回答1: If you really need to, there is no technical reason why you can't do that. The

any way to run 2 loops at the same time?

被刻印的时光 ゝ 提交于 2019-12-11 14:19:31
问题 I want to create a c++ program for a bank queue. Where every 3 minutes a new customer enters the queue. every customer needs 5 minutes for the service. The program print out the information after the first 30 minutes The time of arriving for each customer The time of leaving for each customer How many customers are in the line? Who is the current serving customer? I wrote the current code: #include <queue> #include <ctime> #include <time.h> #include <conio.h> #include <windows.h> #include

Writing Sleep function based on time.After

六眼飞鱼酱① 提交于 2019-12-11 13:58:07
问题 EDIT : My question is different from How to write my own Sleep function using just time.After? It has a different variant of the code that's not working for a separate reason and I needed explanation as to why. I'm trying to solve the homework problem here: https://www.golang-book.com/books/intro/10 ( Write your own Sleep function using time.After ). Here's my attempt so far based on the examples discussed in that chapter: package main import ( "fmt" "time" ) func myOwnSleep(duration int) {