sleep

How can I perform a short delay in C# without using sleep?

不问归期 提交于 2019-11-28 06:48:56
I'm incredibly new to programming, and I've been learning well enough so far, I think, but I still can't get a grasp around the idea of making a delay the way I want. What I'm working on is a sort of test "game" thingy using a Windows forms application that involves a combat system. In it, I want to make an NPC that does an action every couple of seconds. The problem is, I also want to allow the player to interact between attacks. Thread.sleep really doesn't seem to work for me not only because I don't know how to multithread, but whenever I try to run it, say, like this: textBox1.Text += "\r

NetBeans / Java / New hint: Thread.sleep called in loop

柔情痞子 提交于 2019-11-28 05:40:42
In NetBeans, there's a new hint that says: Thread.sleep called in loop. Question 1: How/when can it be a problem to sleep in a loop? Question 2: If it's a problem, what should I do instead? UPDATE: Question 3: Here's some code. Tell me in this case if I should be using something else instead of Thread.Sleep in a loop. In short, this is used by a server which listens for client TCP connections. The sleep is used here in case the max number of sessions with clients is reached. In this situation, I want the application to wait until a free session becomes available. public class SessionManager {

Android: Sleep stages/levels on an Android device?

﹥>﹥吖頭↗ 提交于 2019-11-28 05:33:12
Is there a notion of sleep stages/levels on Android? From browsing the mailing lists, I'm aware that there exist a stage called "Deep Sleep". Do execution for all apps halt when device reaches this state? If so, besides user hitting the power button, what else could wake the device back up? CommonsWare From browsing the mailing lists, I'm aware that there exist a stage called "Deep Sleep". There is not really a separate stage called "deep sleep". There is only "awake", "asleep", and "off". Do execution for all apps halt when device reaches this state? Execution of all processes ceases when the

WHY does Thread.sleep() clear the interrupted flag?

為{幸葍}努か 提交于 2019-11-28 05:16:45
问题 I know that some Thread methods clear the interrupted flag (e.g. sleep, wait, ...). But why do they do this? What is the reason for it? 回答1: That is a result of interruption being designed not to be totally synonymous with cancellation. The guidance from Oracle is to use interruption only for cancellation, but that view may have been arrived at over time. In any event the design doesn't force that. You can design a task to respond to interruption, then go back to what it was doing. In Java

What's the algorithm behind sleep()?

萝らか妹 提交于 2019-11-28 03:34:05
Now there's something I always wondered: how is sleep() implemented ? If it is all about using an API from the OS, then how is the API made ? Does it all boil down to using special machine-code on the CPU ? Does that CPU need a special co-processor or other gizmo without which you can't have sleep() ? The best known incarnation of sleep() is in C (to be more accurate, in the libraries that come with C compilers, such as GNU's libc), although almost every language today has its equivalent, but the implementation of sleep in some languages (think Bash) is not what we're looking at in this

Tell Ruby Program to Wait some amount of time

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 02:44:18
How do you tell a Ruby program to wait an arbitrary amount of time before moving on to the next line of code? rcoder Like this: sleep(num_secs) The num_secs value can be an integer or float. Also, if you're writing this within a Rails app, or have included the ActiveSupport library in your project, you can construct longer intervals using the following convenience syntax: sleep(4.minutes) # or, even longer... sleep(2.hours); sleep(3.days) # etc., etc. # or shorter sleep(0.5) # half a second Use sleep like so: sleep 2 That'll sleep for 2 seconds. Be careful to give an argument. If you just run

PHP output text before sleep

时间秒杀一切 提交于 2019-11-28 01:13:39
I want PHP to output some text, then sleep for a second and a half, and then output some more text. <?php echo 'Output one.'; usleep(1500000); echo 'Output two.'; ?> My problem is that all text is being put out simultaneously - after having waited those 1.5 seconds. I have read something about a function called flush - but it doesn't seem to work. Maybe I'm not using it write. Any help would be appreciated ^^ Thanks in advance! check this out <?php ob_start(); echo 'Output one.'; ob_flush(); usleep(1500000); echo 'Output two.'; ob_flush(); ?> Pentium10's answer did not quite work for me..

What happens to timer in standby mode? [closed]

爷,独闯天下 提交于 2019-11-28 00:54:57
I'm using Timer from Timers namespace. What happens to timer when PC goes to sleep or hibernates? I have timer set to 6 hours delay. What will happen in those situations. 1) Timer starts at hour 0 and goes to sleep/hibernation immediately. Then PC wakes at hour 5. Will my timer fire after next 1 hour or after next 6 hours? 2) Timer starts at hour 0 and goes to sleep/hibernation immediately. Then PC wakes at hour 7. Will my timer fire as soon as PC wakes or will it "miss" that one time and fire in next 5 hours? Will it start counting till next event from time of PC waking or from previous

Do sleep functions sleep all threads or just the one who call it?

本小妞迷上赌 提交于 2019-11-28 00:30:27
问题 I am programming with pthread on linux(Centos)? I wanna to threads sleep a short time to wait for something. I am trying to use sleep(), nanosleep(), or usleep() or maybe something can do that. I want to ask that: Do sleep functions sleep all threads or just the one who call it? Any advices or references would be appreciate. void *start_routine () { /* I just call sleep functions here */ sleep (1); /* sleep all threads or just the one who call it? what about nanosleep(), usleep(), actually I

Playing music in sleep/standby mode in Android 2.3.3

北慕城南 提交于 2019-11-27 23:07:57
问题 I am trying to develop a simple media player to play mp3's of the sdcard/music directory for Android 2.3.3. The problem is when I hit the power button or when the device goes to sleep, the music stops. From googling, and searching stackoverflow, I found that I need to use the wake lock options, but no matter what I do, the music stops when the device goes to sleep (Pressing F7 on the emulator stops the music as well). Since I've been fighting this for way too long, I thought I'd ask for help.