sleep

How to use the Swing Timer to delay the loading of a progress bar

自古美人都是妖i 提交于 2019-12-17 22:28:22
问题 I need to find a way to use the Swing Timer with a progress bar. I tried using Thread.sleep(), but it crashed the app when I used it. Any ways to use the Swing Timer instead of the Sleep()? public void piiEros(int dist) { Pii pii = new Pii(); pii.setVisible(true); for(int pc = 0;100 > pc; pc++) { try { Thread.sleep(dist/100); } catch (InterruptedException ex) { Logger.getLogger(Trav.class.getName()).log(Level.SEVERE, null, ex); } pii.pg.setValue(pc); } pii.dispose(); o.Eros(); } NOTES: Pii is

What's the purpose of sleep(long millis, int nanos)?

落爺英雄遲暮 提交于 2019-12-17 19:06:33
问题 In the JDK, it's implemented as: public static void sleep(long millis, int nanos) throws InterruptedException { if (millis < 0) { throw new IllegalArgumentException("timeout value is negative"); } if (nanos < 0 || nanos > 999999) { throw new IllegalArgumentException( "nanosecond timeout value out of range"); } if (nanos >= 500000 || (nanos != 0 && millis == 0)) { millis++; } sleep(millis); } which means the nanos argument doesn't do anything at all. Is the idea behind it that on hardware with

How to suspend a java thread for a small period of time, like 100 nanoseconds?

余生颓废 提交于 2019-12-17 18:50:13
问题 I know Thread.sleep() can make a java thread suspend for a while, like certain milliseconds and certain nanoseconds. But the problem is the invocation of this function also causes overhead. For example, if I want a thread to suspend for 100 nanoseconds, and I call Thread.sleep(0, 100) . The whole cost for this process is invocation_cost + 100 nanosceonds , which may be much larger the what I want. How could I avoid this problem, and achieve my purpose? The reason I need this is that I want to

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

自古美人都是妖i 提交于 2019-12-17 18:16:46
问题 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

ManualResetEvent vs. Thread.Sleep

ぃ、小莉子 提交于 2019-12-17 16:11:09
问题 I implemented the following background processing thread, where Jobs is a Queue<T> : static void WorkThread() { while (working) { var job; lock (Jobs) { if (Jobs.Count > 0) job = Jobs.Dequeue(); } if (job == null) { Thread.Sleep(1); } else { // [snip]: Process job. } } } This produced a noticable delay between when the jobs were being entered and when they were actually starting to be run (batches of jobs are entered at once, and each job is only [relatively] small.) The delay wasn't a huge

Significance of Sleep(0)

时光总嘲笑我的痴心妄想 提交于 2019-12-17 15:54:13
问题 I used to see Sleep(0) in some part of my code where some infinite/long while loops are available. I was informed that it would make the time-slice available for other waiting processes. Is this true? Is there any significance for Sleep(0) ? 回答1: According to MSDN's documentation for Sleep: A value of zero causes the thread to relinquish the remainder of its time slice to any other thread that is ready to run. If there are no other threads ready to run, the function returns immediately, and

implement time delay in c

无人久伴 提交于 2019-12-17 09:40:12
问题 I don't know exactly how to word a search for this.. so I haven't had any luck finding anything.. :S I need to implement a time delay in C. for example I want to do some stuff, then wait say 1 minute, then continue on doing stuff. Did that make sense? Can anyone help me out? 回答1: In standard C (C99), you can use time() to do this, something like: #include <time.h> : void waitFor (unsigned int secs) { unsigned int retTime = time(0) + secs; // Get finishing time. while (time(0) < retTime); //

How do I get my Python program to sleep for 50 milliseconds?

和自甴很熟 提交于 2019-12-17 06:23:11
问题 How do I get my Python program to sleep for 50 milliseconds? 回答1: from time import sleep sleep(0.05) Reference 回答2: Note that if you rely on sleep taking exactly 50 ms, you won't get that. It will just be about it. 回答3: import time time.sleep(50 / 1000) 回答4: can also using pyautogui as import pyautogui pyautogui._autoPause(0.05,1) _autoPause(time1,time2): it Pauses the command for time1*time2 sec time1 refers to how many secs you want time2 refers to repeat how many time both can be floats

How to create javascript delay function [duplicate]

血红的双手。 提交于 2019-12-17 06:10:01
问题 This question already has answers here : What is the JavaScript version of sleep()? (75 answers) Closed 5 years ago . I have a javascript file, and in several places I want to add a small delay, so the script would reach that point, wait 3 seconds, and then continue with the rest of the code. The best way that I thought of doing this was to create a function, which I could call from anywhere in the script. function startDelay(lengthOfDelay) { //code to make it delay for lengthOfDelay amount

Calling sleep(5); and updating text field not working

£可爱£侵袭症+ 提交于 2019-12-17 03:19:41
问题 I'm trying to sleep a method (see below), but rather than the textLabel changing from the value of myTextLabelString , waiting 5 seconds, changing to "sleep 5 worked", waiting 5 seconds and finally changing to "sleep 5 worked second time round".... it just goes from the value of myTextLabelString , waits 10 seconds, and then changes to "sleep 5 worked second time round". - (void)textLabelChanger:(id)sender { NSString *myTextLabelString = [NSString stringWithFormat:@"%d", gameCountDown];