sleep

measuring time of a profiled “Sleep” function

微笑、不失礼 提交于 2019-12-02 13:03:18
问题 A few days ago I posted this question: measuring time of a profiled function (I hope it's ok i'm opening a new thread, I just can't find the old one in the few first pages) I noticed that in my profiled process, I call a "Sleep" method - and this is the problem... When I call SuspendThread/ResumeThread - The Sleeping process pauses, but in reality - time moves on! I figure that "Sleep" is just some kind of a loop that takes the time and stops whenever the difference between the start time and

Java Sleep not working in loop [closed]

百般思念 提交于 2019-12-02 12:24:01
What I want to do in my java program is, that when I press the button it displays text in textfield in intervals of time. i.e I press the button then a jFrame pops up and there is a label which shows text like: 1st second:"1st" then a time lag of say 1 sec then 2nd thing: "2nd" I am a newbie and I tried to Google this problem but I couldn't find a solution even after 3-4 hours I tried a lot of things: sleep, try n catch... Please write the answer very simplified. Here is my code: In the following code, when the button is pressed, the jFrame comes but has a white screen in it and when the sum

C# Thread.Sleep(1000) takes much more than 1000ms on some pc

五迷三道 提交于 2019-12-02 10:22:34
I write a c# program to count down 5 seconds. What I do is: new Task(() => { try { this.Invoke((Action)delegate() { label1.Text = "5"; // 4, 3, 2..etc }); } Thread.Sleep(1000); } catch { // form could be disposed break; } } }).Start(); This works on my PC, however, when I copied the program to a window tablet, the Thread.Sleep(1000) gives more than 1 second. In other words, it takes more than 5 seconds (in fact more than 10 seconds) to update the label from 5,4,3,2,1. Alternatively, it takes too long to update label1.Text = "5", etc? It does not make sense to me. I wonder what is wrong? Sleep

Accurate sleep/delay within Python while loop

℡╲_俬逩灬. 提交于 2019-12-02 09:53:34
I have a while True loop which sends variables to an external function, and then uses the returned values. This send/receive process has a user-configurable frequency, which is saved and read from an external .ini configuration file. I've tried time.sleep(1 / Frequency), but am not satisfied with the accuracy, given the number of threads being used elsewhere. E.g. a frequency of 60Hz (period of 0.0166667) is giving an 'actual' time.sleep() period of ~0.0311. My preference would be to use an additional while loop, which compares the current time to the start time plus the period, as follows:

Why are all of my threads sleeping using sleep()?

随声附和 提交于 2019-12-02 09:21:19
I saw the following piece of code regarding threading in Linux on the web. But when I run it, all the threads seem to sleep instead of just the main thread. Why? Also, without sleep(5), the statement-"Thread created successfully" runs 3 times instead of 2? Can someone please explain this behavior? Thanks Compiled using: gcc -pthread check.c and my o/p: First thread processingn Thread created successfullyn Second thread processingn Thread created successfullyn The first two lines are printed with a lag of 5sec and the next 2 after 5 more sec. Why are the child threads getting slept instead of

Java Thread及其synchronized,wait,sleep,join,yeid,interrupt

浪子不回头ぞ 提交于 2019-12-02 09:05:48
Java SE7 API - Thread: http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#yield%28%29 参考资料: http://blog.csdn.net/lqqmisslll/article/details/54208491 一、线程的简介 当JVM启动的时候, 通常会有一个独立的非守护线程(也就是类中的main方法所在的线程).JVM会继续运行,除非发生以下情况: Runtime类的exit()方法被调用,并且安全管理者允许退出发生。 所有非守护线程都已经死了,不管是从run方法中返回的还是因为run方法中抛出了异常。 注意:当所有非守护线程都执行结束(包括主线程),那么守护线程也会退出。因为守护线程是无法脱离非守护线程而独自存在的。 二、创建线程有两种方式: 方法1:声明一个类作为Thread的子类(extends Thread),子类重写(override)Thread类的run()方法。子类的实例可以被分配和start。 //比如:该线程用来计算比指定起始值大的素数。 class PrimeThread extends Thread { long minPrime; PrimeThread(long minPrime) { this.minPrime = minPrime; }

Wait() & Sleep() Not Working As Thought

旧时模样 提交于 2019-12-02 08:48:15
Using JavaFX 8.0 and JRE 1.8.0 u45 in IntelliJ, I created a basic pixel editor app. I have two windows(stages). One is a 32x128 matrix of Circle Objects placed in a Grid Pane and the other, a Tools widow; I have one Controller.java . Using the mouse, the Tools window provides tools to draw lines, rectangles, etc. and a menu for Setup, Files and Playlists. The Files menu presents the user with Open, SaveAs and Delete. To view a saved pixel art file, the user clicks Open and via the JFileChooser , the selected file is opened and each Circle’s assigned color is displayed using the following

How to load the script file immediately (dynamically added) before continue?

落爺英雄遲暮 提交于 2019-12-02 08:19:18
问题 I have loaded script file like below code in angular home.component.ts file export class HomeComponent { constructor() { this.loadDynmicallyScript(); } public loadDynmicallyScript() { var script = document.createElement('script'); script.src = "../node_modules/xxxxxx/i18n/xx.min.js"; script.async =false; document.head.appendChild(script); } But this file gets loaded after components created and later. So, in this case, it makes no use of this file. I want to load this file once I appended in

Java Swing Restart Timer After Operation

此生再无相见时 提交于 2019-12-02 07:55:38
I need my timer to restart or at least add another delay after a certain line of code is performed. private static class ButtonHandler implements ActionListener { public void actionPerformed (ActionEvent e) { final JButton button = (JButton)e.getSource(); Timer timer = new Timer(1000, new ActionListener() { public void actionPerformed(ActionEvent e) { String tc = random(); them.setText("They chose: " + tc + "!"); if (button == rock) { whoWins("rock", tc); } else if (button == paper) { whoWins("paper", tc); } else if (button == scissors) { whoWins("scissors", tc); } yourWins.setText("Your wins:

Python 2.x - sleep call at millisecond level on Windows

狂风中的少年 提交于 2019-12-02 06:52:55
I was given some very good hints in this forum about how to code a clock object in Python 2. I've got some code working now. It's a clock that 'ticks' at 60 FPS: import sys import time class Clock(object): def __init__(self): self.init_os() self.fps = 60.0 self._tick = 1.0 / self.fps print "TICK", self._tick self.check_min_sleep() self.t = self.timestamp() def init_os(self): if sys.platform == "win32": self.timestamp = time.clock self.wait = time.sleep def timeit(self, f, args): t1 = self.timestamp() f(*args) t2 = self.timestamp() return t2 - t1 def check_min_sleep(self): """checks the min