sleep

Strange behaviour of function Sleep() used in repeat until in Delphi

别来无恙 提交于 2019-12-01 17:42:26
I have function which is reaction on button click. When I click on the button it should start repeat and write values form an array and show them in labels on main form. Problem is with function sleep - there is some bug or something, cause when I click on the button it waits quite a long time and then it finaly start the action but very quickly. Let's look at my code. Thx for advices. procedure TForm1.ButtonMereniClick(Sender: TObject); var iterator: Integer; begin iterator := 1; repeat //write some values stored int arrays to labels on form LabelTeplota.Caption:='Teplota: '+FloatToStr

Is there an equivalent Javascript or Jquery sleep function?

拥有回忆 提交于 2019-12-01 17:27:49
问题 I want something like this in javascript. for (i = 0; i < 10; i++) { alert(i); // now sleep 1 sec sleep(1000); } is there a built in Javascript or Jquery for this? Thank you! 回答1: There's no such thing, directly. You would have to tell javascript to wake 'something' up after some time using setTimeout . This 'something' would be the code that you plan to execute after the sleep, of course. From an example I found on the internet: function dothingswithsleep( part ) { if( part == 0 ) { alert(

What should I use Sleep or Timer

北城以北 提交于 2019-12-01 17:24:37
问题 I have two alternative using timer or using sleep, I need to call a method every 3 seconds after this method is finished, I wrote basic example to demonstrate what I mean: public static void Main() { new Thread(new ThreadStart(fooUsingSleep)).Start(); callToMethodAfterInterval(new Action<object, ElapsedEventArgs>(fooUsingTimer), 3000); } public static void fooUsingSleep() { Console.WriteLine("Doing some consuming time work using sleep"); Thread.Sleep(3000); fooUsingSleep(); } public static

if Thread.sleep is static, how does individual thread knows it is put to sleep?

女生的网名这么多〃 提交于 2019-12-01 16:20:20
I am a bit confused with Thread.sleep() method. if Thread.sleep() is a static method, how does two threads know which is put to sleep. For example, in the code below, I have two three Threads main , t and t1 . I call Thread.sleep() always. Not t.sleep() . Does it mean Thread.sleep() puts the current Thread to sleep? That means a Thread instance puts to sleep by itself by calling the static method. what if t1 wants to put t to sleep. that shouldn't be possible correct? public class ThreadInterrupt { public static void main(String[] args) throws InterruptedException { System.out.println(

Qt detect when computer goes into sleep?

不想你离开。 提交于 2019-12-01 16:15:44
How can i detect when a users computer goes into sleep (laptop lid closes, sleep mode due to inactivity, etc)? I need to do this to disconnect the users TCP connection. Basically we got a simple chat application where we want to take the user off-line. There is no Qt way to detect when computer goes to sleep or hibernation. But there are some platform dependent ways to do it. On Windows you can listen for the WM_POWERBROADCAST message in your WindowProc handler: LRESULT WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { if (WM_POWERBROADCAST == message && PBT_APMSUSPEND == wParam

Are longer sleeps (in C++) less precise than short ones

大兔子大兔子 提交于 2019-12-01 15:45:09
I have a task to do something every "round" minute(at xx:xx:00) And I use something like const int statisticsInterval=60; time_t t=0; while (1) { if (abs(t-time(NULL)==0)) //to avoid multiple calls in the same second that is the multiple of 60 boost::this_thread::sleep(boost::posix_time::seconds(2));//2, not 1 to make sure that 1 second passes t=time(NULL); boost::this_thread::sleep(boost::posix_time::seconds(statisticsInterval-(t%statisticsInterval))); //DO WORK } As you can see I use sleep (60sec - number of elapsed seconds in current minute). But one programmer told me that it is not

why ImageView can't update before SystemClock.sleep()

↘锁芯ラ 提交于 2019-12-01 11:48:57
I want to show other image in ImageView within 3 second, after that rollover old image. The code: OnClickListener oc = new OnClickListener() { @Override public void onClick(View v) { ImageView iv = (ImageView)v; iv.setImageResource(img2_id); SystemClock.sleep(3000); iv.setImageResource(img1_id); } } myImageView.setOnClickListener(oc); But it doesn't work? So, am I doing something wrong? You are blocking the UI thread. Thus during the sleep command, the screen won't refresh. What you need is to schedule a non-blocking delayed call to a function which changes image resource. Here is a modified

Why is minimum Threading.Timer interval 15ms despite timeBeginPeriod(1)

落爺英雄遲暮 提交于 2019-12-01 08:47:14
The following snippet [DllImport("winmm.dll", EntryPoint = "timeBeginPeriod")] public static extern uint TimeBeginPeriod(uint uMilliseconds); static void Main(string[] args) { if (TimeBeginPeriod(1) != 0) Console.WriteLine("TimeBeginPeriod failed!"); Console.WriteLine("Sleep"); Stopwatch sw = Stopwatch.StartNew(); for (int i = 0; i < 10; i++) { Thread.Sleep(1); Console.WriteLine(sw.ElapsedTicks * 1000d / Stopwatch.Frequency); sw.Restart(); } Console.WriteLine("Threading.Timer"); sw = null; System.Threading.Timer t = null; int n = 0; t = new Timer(state => { if (sw == null) sw = Stopwatch

Python Scheduler vs loop + sleep

瘦欲@ 提交于 2019-12-01 07:42:36
问题 the following is: python sched: from time import time, sleep from sched import scheduler def daemon(local_handler): print 'hi' local_handler.enter(3, 1, daemon, (local_handler,)) if __name__ == '__main__': handler = scheduler(time, sleep) handler.enter(0, 1, daemon, (handler,)) handler.run() python loop + sleep: from time import sleep while True: print 'hello' sleep(3) What is the difference between sched and loop+sleep, and sched will stop when the system time is changed? 回答1: The difference

Why is minimum Threading.Timer interval 15ms despite timeBeginPeriod(1)

廉价感情. 提交于 2019-12-01 06:58:23
问题 The following snippet [DllImport("winmm.dll", EntryPoint = "timeBeginPeriod")] public static extern uint TimeBeginPeriod(uint uMilliseconds); static void Main(string[] args) { if (TimeBeginPeriod(1) != 0) Console.WriteLine("TimeBeginPeriod failed!"); Console.WriteLine("Sleep"); Stopwatch sw = Stopwatch.StartNew(); for (int i = 0; i < 10; i++) { Thread.Sleep(1); Console.WriteLine(sw.ElapsedTicks * 1000d / Stopwatch.Frequency); sw.Restart(); } Console.WriteLine("Threading.Timer"); sw = null;