synchronous

How do I make an eventhandler run asynchronously?

拟墨画扇 提交于 2019-11-27 17:36:45
I am writing a Visual C# program that executes a continuous loop of operations on a secondary thread. Occasionally when that thread finishes a task I want it to trigger an eventhandler. My program does that but the when the event handler is triggered, the secondary thread waits until the event handler is finished before continuing the thread. How do I make it continue? Here is the way I currently have it structured... class TestClass { private Thread SecondaryThread; public event EventHandler OperationFinished; public void StartMethod() { ... SecondaryThread.Start(); //start the secondary

Read all text from stdin to a string

喜夏-厌秋 提交于 2019-11-27 17:14:04
问题 I'm writing a program in Node.js that (in some situations) wants to act as a simple filter: read everything from stdin (up to end of file), do some processing, write the result to stdout. How do you do the 'read everything from stdin' part? The closest solutions I've found so far, seem to work either for one line at a time from the console, or else only work when stdin is a file not a pipe. 回答1: My boiler-plate for this one is a lot like the solution described in a comment above -- offering

Run shell script from Java Synchronously

核能气质少年 提交于 2019-11-27 14:48:40
I am trying to execute a Bash Shell script from Java and it runs fine using this piece of code. public void executeScript() { try { new ProcessBuilder("myscript.sh").start(); System.out.println("Script executed successfully"); } catch (IOException e) { e.printStackTrace(); } } The above code runs fine asynchronously. But what I would like to achieve is to execute the code synchronously. I would like the Java process to wait until the execution of the script is completed and then execute the next batch of code. To summarize, I would like the "Print statement - Script executed successfully" to

Sending one AJAX request at a time from a loop

ぐ巨炮叔叔 提交于 2019-11-27 14:46:25
I know this question has been asked countless times, but I cant figure out for the life of me how to make this answer work in my case: wait for async javascript function to return I'm looping through some "tv channels" in the outerloop and then looping through dates in the week in the innerloop. In the inner loop I make a ajax request to a server to fetch the data and I then store/cache it for later use like so var dates = []; //<-- Contains a list of dates for the coming week var baseUrl = "http://www.someserver.com"; var storedChannels = [1,2,3,4,5,6,7,8,9,10,45,23,56,34,23,67,23,567,234,67

jQuery Deferred and Promise for sequential execution of synchronous and asynchronous functions

天涯浪子 提交于 2019-11-27 14:07:06
问题 If I want to have synchronous and asynchronous functions execute in a particular order I could use jQuery promise but it doesn't seem to work the way I'd expect it to work. Functions a,b and c should execute in that order when in a the deferred.resolve() is called I'd expect function b to be executed but all functions are executed immediately no matter if the resolve is called. Here is the code: function a(){ var deferred = $.Deferred(); setTimeout(function(){ console.log("status in a:"

getJSON Synchronous

☆樱花仙子☆ 提交于 2019-11-27 13:27:26
GOAL: What I'm after is to get data from database and refresh main.php (more evident through draw_polygon) every time something is added in database (after $.ajax to submit_to_db.php). So basically I have a main.php that will ajax call another php to receive an array that will be saved to database, and a json call another php to return an array will be used by main.php. $(document).ready(function() { get_from_db(); $('#button_cancel').click(function(){ $.ajax({ url: 'submit_to_db.php', type: 'POST', data: {list_item: selected_from_list}, success: function(result){ ... get_from_db(); } }); });

Performance difference between Synchronous HTTP Handler and Asynchronous HTTP Handler

南笙酒味 提交于 2019-11-27 12:50:43
问题 Is there a performance difference between Synchronous HTTP Handler and Asynchronous HTTP Handler? IHttpHandler vs IHttpAsyncHandler Why choose one over another? What are the benefits? 回答1: ASP.NET uses the thread pool to process incoming HTTP requests. When an IHttpHandler is called, a thread pool thread is used to run that request and the same thread is used to process the entire request. If that request calls out to a database or another web service or anything else that can take time, the

Asynchronous or Synchronous calling of event handlers in javascript

你说的曾经没有我的故事 提交于 2019-11-27 12:22:39
问题 Are event handlers executed synchronously or asynchronously in JavaScript? Here is JS bin which is showing that event handler is executed synchronously. Code: $('#toclick').bind('custom', function() { for (var i=0; i<100000; i++) {} console.log('Inside click handler'); }); $('#toclick').trigger('custom'); console.log('Outside click handler'); Output: Inside click handler Outside click handler This means if we trigger an event, the code below it won't be executed unless all the event handlers

Sync version of async method

ぐ巨炮叔叔 提交于 2019-11-27 11:08:05
What's the best way to make a synchronous version of an asynchronous method in Java? Say you have a class with these two methods: asyncDoSomething(); // Starts an asynchronous task onFinishDoSomething(); // Called when the task is finished How would you implement a synchronous doSomething() that does not return until the task is finished? Have a look at CountDownLatch . You can emulate the desired synchronous behaviour with something like this: private CountDownLatch doneSignal = new CountDownLatch(1); void main() throws InterruptedException{ asyncDoSomething(); //wait until doneSignal

JS - Can't combine lib files

被刻印的时光 ゝ 提交于 2019-11-27 11:05:28
问题 I have multiple lib files in an an index.html file, that are loaded in proper sequence for an app I am running. <!-- example of some of them... --> <script src="/./sys/lib/jquery.min.js"></script> <script src="/./sys/lib/jquery.ui.min.js"></script> <script src="/./sys/lib/jquery.easing.min.js"></script> <script src="/./sys/lib/underscore.min.js"></script> <script src="/./sys/lib/handlebars.min.js"></script> <script src="/./sys/lib/backbone.min.js"></script> <script src="/./sys/lib/moment.min