async

Threading multiple async calls

匿名 (未验证) 提交于 2019-12-03 02:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Part of my Silverlight application requires data from three service requests. Up until now I've been chaining the requests so as one completes the other starts... until the end of the chain where I do what I need to do with the data. Now, I know thats not the best method(!). I've been looking at AutoResetEvent (link to MSDN example) to thread and then synchronize the results but cannot seem to get this to work with async service calls. Does anyone have any reason to doubt this method or should this work? Code samples gratefully received! 回答1

WinRT async data load in constructor

匿名 (未验证) 提交于 2019-12-03 02:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to load some data in the constructor of a ViewModel but due to WinRT's async nature I am forced to use async methods. Unfortunately I cannot have an async constructor so I am trying to use the asynchronous method as a synchronous method. I'm sure there is a much better way of loading data (async) on application load but my mind is drawing a blank at the moment. I'm either looking for a way to fix my app using the line of thought i'm going down, or to fix this permanently using a more appropriate method. The code is very simple (even

IHttpActionResult vs async Task<IHttpActionResult>

匿名 (未验证) 提交于 2019-12-03 02:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Most Web API 2.0 methods I've seen return IHttpActionResult , which is defined as an interface that "defines a command that asynchronously creates a System.Net.Http.HttpResponseMessage". I'm a little confused about what's going on when a method is returning async Task . Why would you use one over the other? Or are these functionally identical - isn't IHttpActionResult already asynchronous? 回答1: The difference between using IHttpActionResult and async Task is whether any of your code utilizes the async and await feature. Many libraries like

Node.js async to sync

匿名 (未验证) 提交于 2019-12-03 02:05:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How can I make this work var asyncToSync = syncFunc(); function syncFunc() { var sync = true; var data = null; query(params, function(result){ data = result; sync = false; }); while(sync) {} return data; } I tried to get sync function from async one, I need it to use FreeTds async query as sync one 回答1: Use deasync - a module written in C++ which exposes Node.js event loop to JavaScript. The module also exposes a sleep function that blocks subsequent code but doesn't block entire thread, nor incur busy wait. You can put the sleep function in

Potentially async function return a promise that immediately resolves?

匿名 (未验证) 提交于 2019-12-03 02:01:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Where asyncBananaRequest returns a promise - function potentiallyAsync () { if (cachedBanana) { return asyncBananaRequest(); } return ??cachedBanana??; } potentiallyAsync().then(function(banana){ //use banana }) I want a banana, I might already have it cached. Is there a way for me to return the cached banana in the potentiallyAsync functionas a promise that immediately resolves with the cached bananas? I'm currently using the Q lib packaged in Angular, but I'm hoping there's a generic implementation 回答1: While SomeKittens is awesome, his

NodeJS Async: Callback already called?

匿名 (未验证) 提交于 2019-12-03 02:00:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm using Async module in Node.JS to keep track of my asynchronous calls. However, I'm getting an error - "Callback already called." Can someone help me out here? async.each(data['results'], function(result, done) { if (result['twitter_id'] !== null) { //Isolate twitter handle var param = { "user.screen_name": result['twitter_id']} db.test4.find( param, function(err, users) { if( err ) { return done(err); } else if (!users) { res.send("No user found"); } else { users.forEach( function(Result) { twitter_ids.push(Result); //console.log(Result)

How can I tell if a C# method is async/await via reflection?

匿名 (未验证) 提交于 2019-12-03 01:59:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: e.g. class Foo { public async Task Bar() { await Task.Delay(500); } } If we are reflecting over this class and method, how can I determine if this is an actual async/await method rather than simply a method that happens to return a Task? class Foo { public Task Bar() { return Task.Delay(500); } } 回答1: In my copy of your code, the MethodInfo for the async method contains the following items in the CustomAttributes property: a DebuggerStepThroughAttribute a AsyncStateMachineAttribute whereas the MethodInfo for the normal method contains no

Async TCP Server - Message Framing Advice

匿名 (未验证) 提交于 2019-12-03 01:57:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have an asynchronous TCP socket server in C# that I've made using the TcpListener/TcpClient wrappers for Socket. I'm pretty new to networking in general so I was unaware of how TCP treats data sent, and how it doesn't preserve the message boundaries. After a little research I think I've come up with a solid solution but I'm wondering if anyone has more advice for me. Currently the data I'm sending is a byte[] of a serialized class object using protobuf (Google's data exchange library) https://code.google.com/p/protobuf/ After I serialize

Should I use await with async Action method?

匿名 (未验证) 提交于 2019-12-03 01:57:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I need to implement an asynch Action in my Controller for a long running external API call. Looking at some tutorials, I have implemented my method like this: [AsyncTimeout(200)] public async Task DoAsync() { // Execute long running call. return View(); } My question is, is this enough to make is truly non-block asynchronous? Do I also need to apply the await operator, and if so how should I do that? 回答1: I need to implement an asynch Action in my Controller for a long running external API call. ... My question is, is this enough to make is

Android - Async Task behavior in 2.3.3 and 4.0 OS

匿名 (未验证) 提交于 2019-12-03 01:57:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am testing an application where we have a list view with list of images retrieved over network. When i run the application on android device 2.3.3 (WIFI speed 512 KBPS) and check the DDMS (Thread Viewer), the number of threads keeps increasing till 50 from 25. But when i test the same application on device 4.0 (WIFI speed 5 MBPS), number of threads did not increase. Can anyone help me understand why this is happening ? Is it due to android OS difference or any other reason ? Thanks in advance. 回答1: Are you useing AsyncTask .