FAQ Database Discussion Community


Update a buttons UIImage while a counter decreases iOS

ios,objective-c,nstimer,sleep
I am trying to change a UIButton's UIImage every second, until a counter reaches 0. I have tried NSTimer, performSelector withDelay but I could not get either of those to work, plenty of googling came up with different options but pointed to the fact I can't update the UI when...

Lua microseconds sleep

lua,sleep
Ok, I need to wait (for instance) for 10 us in my lua script. Is there any way to do it? For now I use this simple (non busy-waiting) function using socket: function my_utils.sleep(sec) socket.select(nil, nil, sec) end but it seems its "sleep minimum" is milliseconds. Example 1: for x=0,2*math.pi,0.008...

C++ Print one letter at the time. How to?

c++,windows,sleep
Let's say i have a string, that contains a message. If i want to print it on the screen, i just can do cout<<string, or cout<<"Hello!". But the message gets printed all at once. So what i am looking for is a function that takes a message and a number...

Is it ok to use sleep() in a loop to be nice?

python,multithreading,loops,sleep
I couldn't describe the question better. this is from redis-py github page. >>> while True: >>> message = p.get_message() >>> if message: >>> # do something with the message >>> time.sleep(0.001) # be nice to the system :) I thought this style of coding (sleep in a loop) isn't so...

Change JLabel and wait for sometime to exit

java,sleep
I want to change the label when I click the button, and then after 3 seconds exit the program. But if I click the button, label does not change. It just exits after 3 seconds. This is my logic Change the label. Sleep for 3 seconds Then exit the program....

Can I sleep/hibernate the PC from a windows store app?

hibernate,windows-store-apps,sleep
I just want to make a button to sleep the PC: <Button Clicked="Button_Clicked">Sleep</Button> ...

C sleep method obstructs output to console

c,printf,sleep
I have a C program, where I just wanted to test if I could reproduce a console spinner used in npm install while it installs a module. This particular spinner simply spins in this order: | / - \ on the same space, so I use the following program: #include...

Sleep Shiny WebApp to let it refresh… Any alternative?

r,shiny,sleep
I have a WebApp that have some renderUI({})... and some of them depend on the input of another. This makes that, briefly, a red error in the webpage appear when I select some options. Because the if() clause of some renderUI({}) depend on the input of a selectizer. The error...

SLEEP(x) role in SQL query clarification

mysql,sql,sleep
I don't understand the reason why this happens. Could somebody explain it? SELECT * FROM users WHERE name = '' returns 0 records as it should SELECT * FROM users WHERE name = 'janet' returns 1 record as it should SELECT * FROM users WHERE name = ''-SLEEP(3) returns EVERY...

What is the best way to program a delay in Delphi?

delphi,events,timer,delphi-xe2,sleep
A Delphi application that I'm working on must delay for one, or sometimes two, second(s). I want to program this delay using the best practices. In reading entries about Delphi's Sleep() method on stackoverflow, I found these two comments: I live by this maxim: "If you feel the need to...

JFrame: Sleep between statements

java,multithreading,swing,sleep,thread-sleep
I'm still very new to the world of programming and have recently noticed, that whenever I tell the programm to idle for some seconds between the code, it instead sleeps at the start and then goes through the remaining code. I've tried various ways like thread.sleep() or Timers but I...

Timeout handle email php

php,email,redirect,location,sleep
I would like to redirect my user to a new page, but the current site continues to run a script that sends a threaded message 10 minutes later at a specified address. I tried something like this: Header('Location: xy.com'); sleep(100); do_the_email_sending_here(); But actually it doesn't worked,because the site waited for...

Java multi-threading scope of Thread.sleep

java,multithreading,concurrency,scope,sleep
According to Oracle's documentation for Thread.sleep: Thread.sleep causes the current thread to suspend execution for a specified period. I am wondering what is considered the current thread. I have a simple interface called Function: public interface Function { public abstract void run(TomVM vm); } And a class that contains instances...

why putting \n alters the order of execution

c++,c,sleep,zombie-process
while I am trying to code in c for zombie process simulation ,I am getting alteration in output due to putting of \n in printf statements: code1: main() { int id; id=fork(); if(id>0) { printf("Parent will sleep");//pf1// sleep(5); //system("ps -u"); } if(id==0) printf("I am child");//pf2// } output: I am childParent...

python time.sleep() delays previous commands

python,time,tkinter,sleep
When trying to interrupt a tkinter application, it seems that time.sleep() puts some previous command on the hold. According to my understanding and previous experiences, label1's text should be set to "before" for one second and then changed to "after". However, the "before" value never shows up and "after" gets...

Should PHP sleep after a MySql Insert when that INSERT is required right after success?

php,mysql,sleep
PHP - > Inserts VALUE into MySql database on FILE1.php -- Success: Redirects to FILE2.php?ID=(Last_Id) -- PHP - > Requires (Last_Id) to work fine. Question: Should PHP sleep 1 second before redirecting, when the mentioned database contains 100k+ rows, to avoid any possible problem, or is that in-necessary? I tried...

Whats the difference between using boost::this_thread::sleep_for() and regular sleep() function?

c++,boost,sleep,boost-thread
We know that boost::this_thread::sleep_for(...) can be used for putting the currently running thread into sleep. How different it is from the regular sleep() function. It seems everyplace where we use boost::this_thread::sleep_for(...) can be simply replaced by sleep() method without affecting the results. Can anyone throw some light into it.

Wait for a time frame in Java: how does Thread.sleep(int) work?

java,multithreading,sleep
Conventionally, I delay my programs for a short time with Thread.sleep(int) surrounded with an e.printStackTrace() try/catch block. I want to do away with the exception handling. I wrote this function: private static void pause(int millis) { long end = System.currentTimeMillis() + millis; while(System.currentTimeMillis() <= end) { // Do nothing }...

make java wait until variable changes

java,multithreading,sleep
I want to make my code wait until there is a change anywhere in my class to the variable finaloutcomes. Is there any way to do this? I am carrying this out within an Asynctask, which I posted below. public HashMap<String,String> checkbetoutcome() { new LoadAllGamet().execute(); // INSERT CODE HERE return...

Can I guarantee that Sleep() would not sleep for more than 10 ms?

c++,winapi,sleep
I know that Sleep() is not accurate, but is there's a way to make it not sleep for more than 10 ms (i.e. only sleep between 1 ms and 10 ms)? Or does Sleep(1) already guarantee that?

Delphi: Creating and Reading a text file is causing an I/O 32 error. Should this be prevented using sleep?

windows,delphi,sleep
I am currently working on a program that needs to be able to report whether or not Windows has been activated. function TSoftwareReport.getLicenceInfo : String; var Activated : String; LicenceFile : TextFile; begin // redirect command output to txt file ShellExecute(0,nil,'cmd.exe', '/C cscript %windir%\system32\slmgr.vbs/xpr > C:\Activated.txt', nil, SW_HIDE); //Read the...

c++ sleep(0) loop behaviour

c++,linux,time,sleep
My question concerns the running time of a loop of sleep(0) operations and the number of parameters passed as arguments. Consider the following snippet: #include <iostream> #include <cstdlib> #include <unistd.h> int main(int argc, char ** argv) { int i; int N = 10000000000; if(argc > 2) N = std::atoi(argv[1]); clock_t...

Mac OS X Terminal: Run Song when Computer is Asleep?

osx,audio,terminal,sleep
How should one write the afplay "Song/Here" command in terminal on Mac OS X, in order for it to run when the computer is in sleep mode? In other words, through only terminal, how can one play a song/sound of sorts when the computer is asleep? ...

PHP Sleep() Function Doesn't work, else stament keep reading old file

php,if-statement,sleep
ignore_user_abort(); set_time_limit(0); $interval=60; $flag=true; file_put_contents("log.log","Starts \r\n"); while($flag){ date_default_timezone_set("America/New_York"); $mytime=date("y/m/d h:i:sa"); $file = fopen("C:/work/testData/test.txt","r"); $myfile=fread($file,filesize("C:/work/testData/test.txt")); if(stristr($myfile,"Finish writing tables")){ file_put_contents("log.log","Finished! Ready To Send Email $mytime \r\n",FILE_APPEND); $flag=false; }else{ file_put_contents("log.log","Still Running $mytime $myfile...

pause an activity meanwhile another one is running

android,multithreading,sleep,voice
I would like to get voice recognition using just one method. In order to do that i've created 3 classes the main class public class Index extends Activity { private Button boton; private EditText texto; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_index); boton = (Button)findViewById(R.id.boton); texto = (EditText) findViewById(R.id.texto);...

How to detect in a bash script that the parent session has finished ?

linux,bash,sleep
Let be a bash script with an infinite loop and a sleep. We start it in the background. If the user logs out, I would like to be able to know it in the script. How can I know from within the script that the parent session has been closed...

regarding sleep command in c++

c++,time,sleep
I am trying to delay the program using sleep command. But when I print the results, I don't see the delay. Am I missing something . #include <iostream> #include <stdlib.h> #include <ctime> #include <string.h> #include <sys/time.h> // for time #include <unistd.h> // for microsecond sleep using namespace std; const std::string...

Delphi and sleep function

delphi,timer,sleep
I am having some issues regarding the sleep function. I have my application which executes an external command with some options: str := 'C:\BERN52\MENU\menu.exe C:\BERN52\GPS\PAN\DAILY.INP C:\GPSUSER52\WORK\MENUAUX_DAILY.INP'; WinExec(Pansichar(str), SW_Shownormal); After that when this process is finished I should kill it and continue with another things. I did the following: Sleep(60000*StrToInt(Form1.Edit11.Text)); winexec('taskkill...

C# appliction background worker - Thread.Sleep stops UI

c#,backgroundworker,sleep
I'm making a C# app to monitor some stuff in SQL. I use a background worker to pick up SQL data then build some charts based on the data. Pretty basic. However there's one frustrating thing about this. Using Thread.Sleep in the worker completely locks up the UI. No loading...

Why won't _sleep(1000) compile in Xcode?

c++,windows,sleep
I have a program that is supposed to count down from 10 to 0, and every time it counts down it's supposed to wait one second then flush the output using cin.flush(). The professor demonstrated this in class and it worked perfectly, however, when I get home Xcode gives me...

Is this a correct use of sleep()?

c,sleep
I'm using sleep like this to grab a frame every 1/25th of a second. OS is Debian 6 armel. #define VIDEO_FRAME_RATE 25.0f while (RECORDING) { sprintf(buffer, "Someting from a data struct that is updated\n"); fprintf(Output, buffer); usecTosleep = (1.0f/VIDEO_FRAME_RATE) * 1000000; usleep(usecToSleep); } Question: What is the guarantee that the...

Time.sleep inaccurate for Python counter?

python,python-2.7,time,sleep
I'd like to create a revenue counter for the sales team at work and would love to use Python. E.g. Joe Bloggs shifts his target from 22.1 to 23.1 (difference of 1.0.) I'd like the counter to tick evenly from 22.1 to 23.1 over an hour. I've created this script,...

Time management for real-time applications

python,sleep,python-multithreading
How to generate precise pulses with python? from threading import Thread import time def runA(): while True: print "a" sendSignal(1) time.sleep(0.0001) sendSignal(0) time.sleep(0.005) if __name__ == "__main__": t1 = Thread(target = runA) t1.setDaemon(True) t1.start() while True: sleep(10) time management in python is not precise. specially to create multi-threaded PWM generators...

Adding a pause to a graphical output

java,multithreading,swing,graphics,sleep
I've created a program to handle directed graphs. I also used a raster to display the graph. (I'm still working on cleaning it up, although it should be sufficient to show the computations.) I want a pause in the graphing, so as the items change color during the search it's...

Php schedule run a function after 10 minutes

php,cron,scheduled-tasks,sleep
There is a function A and function B What I would like to do is , after running function A, it start the counting , after 10 minutes it run the function B (for one time only). Notice that during the counting, the function A can be run again ,...

how to make a counter in linux?

linux,shell,sleep
I'm trying to write a script where I want to make a countdown of three seconds (probably with the sleep command), but every second I want to display the text "break". After every second, I want to display a countdown next to the word "break", but the line of text...

Can std::this_thread::sleep_for() have spurious wakeups?

c++,c++11,stl,sleep,thread-sleep
Note, this is not a question about std::condition_variable::wait_for(). I know that can wake spuriously. My program’s behavior suggests the answer to this question is Yes, but the STL documentation is quite clear for the condition_variable case. At least at cppreference.com, the correct answer for this_thread appears to be No. Compiler...

Does sleep/nanosleep work by utilizing a busy wait scheme?

c++,c,posix,sleep
I am wondering how is sleep/nanosleep internally implemented? Consider this code: { // on a thread other than main() thread while(1) { //do something sleep(1); } } would the CPU be doing constant context switching to check if sleep of 1 sec is done (i.e. an internal busy wait). I...

How make the script wait/sleep in a simple way in unity

c#,unity3d,monodevelop,sleep,wait
How can put between the TextUI.text = .... a sleep function, for wait 3 seconds between each phrase? public Text GuessUI; public Text TextUI; [...truncated...] TextUI.text = "Welcome to Number Wizard!"; TextUI.text = ("The highest number you can pick is " + max); TextUI.text = ("The lowest number you can...

Bash Xargs Sleep (Multiple Command Line Arguments)

bash,sleep,xargs
Ok so I have the following script that updates Route43 DNS entries. Unfortunately there is a limit to the number of calls per second you can make so I need to make the final Xargs command sleep for about a second between each iteration. I've tried a couple of things...

How can I put the current thread to sleep?

rust,sleep
There is so much outdated information, it is really hard to find out how to sleep. I'd like something similar to this Java code: Thread.sleep(4000); ...