wait

Wait for n seconds, then next line of code without freezing form

橙三吉。 提交于 2019-11-29 01:24:17
Hi I am trying to find a method of waiting a number of milliseconds before moving to the next line of code, I have looked into Thread.Sleep but this will freeze the main form, I would like this to remain active. I tried timers and stopwatches and both freeze the main form when they should be posting to a console when they tick. I couldn't find a way of using task.delay or background worker in the wait I wanted either. Pseudo Code: Wait 2 - 6 seconds Log "waiting" Log "waiting" Log "waiting" Stop Waiting - Run next line of code. The methods I have tried just freeze up the form and fill the log

Javascript wait() function [closed]

匆匆过客 提交于 2019-11-28 23:30:15
I want to create a javascript 'wait' function. what should i edit ? function wait(waitsecs){ setTimeout(donothing(), 'waitsecs'); } function donothing() { } Javascript isn't threaded, so a "wait" would freeze the entire page (and probably cause the browser to stop running the script entirely). To specifically address your problem, you should remove the brackets after donothing in your setTimeout call, and make waitsecs a number not a string: console.log('before'); setTimeout(donothing,500); // run donothing after 0.5 seconds console.log('after'); But that won't stop execution; "after" will be

How to differentiate when wait(long timeout) exit for notify or timeout?

こ雲淡風輕ζ 提交于 2019-11-28 22:42:37
Having this wait declaration: public final native void wait(long timeout) throws InterruptedException; It could exit by InterruptedException, or by timeout, or because Notify/NotifyAll method was called in another thread, Exception is easy to catch but... There is any way to know if the exits cause was timeout or notify? EDIT: This is a tricky way that could work, (although I don't like it) long tBefore=System.currentTimeMillis(); wait(TIMEOUT); if ((System.currentTimeMillis() - tBefore) > TIMEOUT) { //timeout } You can't differentiate between the two unless you provide some additional code.

How to use linux `perf` tool to generate “Off-CPU” profile

社会主义新天地 提交于 2019-11-28 21:32:55
问题 Brendan D. Gregg (author of DTrace book) has interesting variant of profiling: the "Off-CPU" profiling (and Off-CPU Flame Graph; slides 2013, p112-137) to see, where the thread or application were blocked (was not executed by CPU, but waiting for I/O, pagefault handler, or descheduled due short of CPU resources): This time reveals which code-paths are blocked and waiting while off-CPU, and for how long exactly. This differs from traditional profiling which often samples the activity of

How can I wait for 10 second without locking application UI in android [duplicate]

北战南征 提交于 2019-11-28 20:07:20
This question already has an answer here: How do you have the code pause for a couple of seconds in android? 1 answer I am stuck with a problem, I want to wait 10 second because I want my application to start the code below after that 10 sec but without stopping that person from clicking anything else in the application ( without calling Thread.sleep(); ). try { Log.v("msg", "WAIT CheckFrequencyRun"); Thread.sleep(10000); // giving time to connect to wifi } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } //if no network if(wifiManager

How to use Fork() to create only 2 child processes?

倖福魔咒の 提交于 2019-11-28 19:33:23
I'm starting to learn some C and while studying the fork, wait functions I got to a unexpected output. At least for me. Is there any way to create only 2 child processes from the parent? Here my code: #include <sys/types.h> #include <stdio.h> #include <unistd.h> #include <sys/wait.h> int main () { /* Create the pipe */ int fd [2]; pipe(fd); pid_t pid; pid_t pidb; pid = fork (); pidb = fork (); if (pid < 0) { printf ("Fork Failed\n"); return -1; } else if (pid == 0) { //printf("I'm the child\n"); } else { //printf("I'm the parent\n"); } printf("I'm pid %d\n",getpid()); return 0; } And Here is

Wait for multiple applications run asynchronously from batch file to finish

假装没事ソ 提交于 2019-11-28 18:53:32
There is a simple Windows batch file that runs multiple instances of application: start app.exe param1 start app.exe param2 Is there a way to run them asynchronously at the same time (which above does) and wait for them both to finish to perform other actions - something like C# Task.WhenAll(tasksList.ToArray()); /* Process tasksList.Result */ ? /wait switch will not help here, some polling for if particular instance is still running maybe. dbenham I suppose this question is slightly different than Waiting for parallel batch scripts in that this application is waiting for .exe processes to

Wait for callback in javascript

ε祈祈猫儿з 提交于 2019-11-28 18:47:11
I'm trying to create a function that returns a object with information of a callback: var geoloc; var successful = function (position) { geoloc = { longitude: position.coords.longitude, latitude: position.coords.latitude }; }; var getLocation = function () { navigator.geolocation.getCurrentPosition(successful, function () { alert("fail"); }); return geoloc; }; How can I do this? The function getLocation return null value before successful is executed. Thanks! Callbacks are used because the function is asynchronous. The callback runs at some point in the future. So, yes getLocation returns

Python subprocess Popen.communicate() equivalent to Popen.stdout.read()?

给你一囗甜甜゛ 提交于 2019-11-28 17:14:33
Very specific question (I hope): What are the differences between the following three codes? (I expect it to be only that the first does not wait for the child process to be finished, while the second and third ones do. But I need to be sure this is the only difference...) I also welcome other remarks/suggestions (though I'm already well aware of the shell=True dangers and cross-platform limitations) Note that I already read Python subprocess interaction, why does my process work with Popen.communicate, but not Popen.stdout.read()? and that I do not want/need to interact with the program after

Wait some seconds without blocking UI execution

﹥>﹥吖頭↗ 提交于 2019-11-28 16:14:22
问题 I would like to wait some seconds between two instruction, but WITHOUT blocking the execution. For example, Thread.Sleep(2000) it is not good, because it blocks execution. The idea is that I call a method and then I wait X seconds (20 for example) listening for an event coming. At the end of the 20 seconds I should do some operation depending on what happened in the 20 seconds. 回答1: I think what you are after is Task.Delay. This doesn't block the thread like Sleep does and it means you can do