wait

Java: How to distinguish between spurious wakeup and timeout in wait()

风格不统一 提交于 2019-11-28 11:12:05
Here is a case where a thread is waiting for notify() or a timeout. Here a while loop is added to handle spurious wake up. boolean dosleep = true; while (dosleep){ try { wait(2000); /** * Write some code here so that * if it is spurious wakeup, go back and sleep. * or if it is timeout, get out of the loop. */ } catch (InterruptedException e) { e.printStackTrace(); } } In this case how can I distinguish between a spurious wake up and time out? If it is a spurious wake up, i need to go back and wait. And if it is a timeout, i need to get out of the loop. I can easily identify the case of notify(

Wait for user input from keyboard in R before next line of code - readline - Rstudio

旧时模样 提交于 2019-11-28 10:21:43
问题 I want the user to choose data before analyzing the data but I can't get the code right to wait for user input… check<-0 count<-0 data.choice<-function(){ while(check < 1 ){ check <-as.numeric(readline('Choose 1 or 2 for analysing Data1 or Data2 respectively: \n 1. "Data1" \n 2. "Data2" ')); check <- ifelse(grepl("\\D",check),-1,as.integer(check)) if(is.na(check)|check>2|count>3){ count<-count+1 print('Please type only 1 or 2...') break} # breaks when hit enter } } data.choice() At this point

Wait one second in running program

蓝咒 提交于 2019-11-28 07:54:14
dataGridView1.Rows[x1].Cells[y1].Style.BackColor = System.Drawing.Color.Red; System.Threading.Thread.Sleep(1000); İ want to wait one second before printing my grid cells with this code, but it isn't working. What can i do? Is it pausing, but you don't see your red color appear in the cell? Try this: dataGridView1.Rows[x1].Cells[y1].Style.BackColor = System.Drawing.Color.Red; dataGridView1.Refresh(); System.Threading.Thread.Sleep(1000); Mark Rowe Personally I think Thread.Sleep is a poor implementation. It locks the UI etc. I personally like timer implementations since it waits then fires.

Synchronous startActivityForResult - Waiting for Activity to Complete

耗尽温柔 提交于 2019-11-28 07:37:20
问题 I have an application where I am launching a new Activity, and need to have the result of the activity before proceeding. I realize that startActivityForResult is asynchronous / non-blocking, and that I can get the result of the activity in the onActivityResult callback. So I guess what I'm looking for is the best way to wait for the activity to return... Something like this perhaps? Or is there a better way? Activity Launcher Function: public String ActivityLauncher() { //Set up Intent

jQuery: Handle fallback for failed AJAX Request

你说的曾经没有我的故事 提交于 2019-11-28 06:44:51
Can jQuery provide a fallback for failed AJAX calls? This is my try: function update() { var requestOK = false; $.getJSON(url, function(){ alert('request successful'); requestOK = true; }); if (!requestOK) { alert('request failed'); } } Unfortunately, even if the callback function of the $.getJSON() method is called, i get the message 'request failed', before the callback function has the opportunity to set the requestOK variable. I think it's because the code runs in parallel. Is there a way to handle such situations? I thought about chaining or some way of waiting for the AJAX request,

Android - Wait for volley response to return

ⅰ亾dé卋堺 提交于 2019-11-28 05:55:47
I need execute a Volley request and wait for the response to parse it and return it, but have no idea on how to achieve this. Can someone help? What I have now is this: public String getLink() { JsonObjectRequest jsObjRequest = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { shortenURL = response.getString("url"); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { // TODO Auto-generated method stub } }); queue.add(jsObjRequest); return shortenURL; } A

How can I make a program wait for a variable change in javascript?

只愿长相守 提交于 2019-11-28 05:11:38
I want to force a JavaScript program to wait in some particular points of its execution until a variable has changed. Is there a way to do it? I have already found an extension that is called "narrative JavaScript" that force the program to wait until an event to happen. Is there a way to create a new event, a "variable change event" for example that behaves like onclick event.. Edit 2018: Please look into Object getters and setters and Proxies . Old answer below: a quick and easy solution goes like this: var something=999; var something_cachedValue=something; function doStuff() { if(something

Selenium WebDriver - How to set Page Load Timeout using C#

[亡魂溺海] 提交于 2019-11-28 04:30:37
I am using Selenium 2.20 WebDriver to create and manage a firefox browser with C#. To visit a page, i use the following code, setting the driver timeouts before visiting the URL: driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5)); // Set implicit wait timeouts to 5 secs driver.Manage().Timeouts().SetScriptTimeout(new TimeSpan(0, 0, 0, 5)); // Set script timeouts to 5 secs driver.Navigate().GoToUrl(myUrl); // Goto page url The problem is that sometimes pages take forever to load, and it appears that the default timeout for a page to load using the selenium WebDriver is 30

Concept behind putting wait(),notify() methods in Object class [duplicate]

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 02:47:05
This question already has an answer here: How can the wait() and notify() methods be called on Objects that are not threads? 9 answers I am just having hard time to understand concept behind putting wait() in Object class. For this questions sake consider if wait() and notifyAll() are in Thread class. class Reader extends Thread { Calculator c; public Reader(Calculator calc) { c = calc; } public void run() { synchronized(c) { //line 9 try { System.out.println("Waiting for calculation..."); c.wait(); } catch (InterruptedException e) {} System.out.println("Total is: " + c.total); } } public

Launch Safari and Wait Until it is Closed [duplicate]

柔情痞子 提交于 2019-11-28 02:26:50
This question already has an answer here: Launch Firefox and Wait until it is Closed 1 answer Question I want to start the Safari web browser as the process to visit a specific website, then wait until it is closed. A special situation is that the browser may already be open and running, as the user may have visited some website already. In that case, the browser would probably open a new tab in an existing window and the newly launched process will be terminated immediately. This should not confuse my waiting process: I either want a new browser window (if that can somehow be enforced, maybe