async-await

Why does this async lambda function invocation not compile in C#?

别来无恙 提交于 2019-12-23 23:24:11
问题 I seem to be missing something really basic in my understanding. I am trying to call an async function that will take a Func<T> passed in by the caller, in case if the async function doesn't find a value in the cache. I am really puzzled as to why my code won't compile. My calling code is as follows static void Main(string[] args) { Func<Task<string>> dataFetcher = async () => { string myCacheValue = await new HttpClient().GetStringAsync("http://stackoverflow.com/"); return myCacheValue; };

Using Task.Wait instead of await for async programming

﹥>﹥吖頭↗ 提交于 2019-12-23 23:11:58
问题 The .Net article on Tasks shows two following two code snippets, one using await and the other using Task.Wait and says both are "functionally equivalent". Isn't that technically incorrect then? Can someone please clarify? Also if Tasks are supposed to be asynchronous and form the basis for Asynchronous Programming (TPL), why would ASP.Net allow a synchronous Wait on them anyway? Doesn't that kind of violate their main utility? using System; using System.Threading.Tasks; public class Example

Difference between .GetAwaiter() and ConfigureAwait() [closed]

末鹿安然 提交于 2019-12-23 23:10:04
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 years ago . Can any one tell me difference between GetAwaiter() and ConfigureAwait(false) . Both of them are used in Async method to solve the deadlock situation and ConfigureAwait to complete task without using Synchrnoization context. I'm looking for scenarios where we can use GetAwaiter()

Can developers “force” the system to prevent “Metro” apps from being suspended while background async processes are running?

吃可爱长大的小学妹 提交于 2019-12-23 23:07:08
问题 When an app is not currently "front and center" in Win8, it is suspended. Does this preclude keeping the app explicitly alive in the background, such as in an email client, using async operations to poll the mail server for new messages, and download them (and then update the Tile with count of new messages)? If this is not possible (a suspended app cannot perform background processing, or cannot force the system to allow it to stay active, albeit not visible), what would be the workaround -

Is it possible for an I/O callback within a .NET Windows Service that calls C#'s await to not block?

别来无恙 提交于 2019-12-23 21:25:04
问题 I know that in ASP.NET that the worker thread goes back to the pool when await is used while the I/O happens in the background, which is great for scalability. My Windows Service is a socket server, and it uses Begin / End style async socket I/O. Mixing my magic, I know. I'm in the EndRead callback, receiving a request to do work. I don't want the thread that made the callback to block. I'm using the Nito.AsyncEx library, using AsyncContext.Run(() => DoMyBiddingHopefullyInTheBackground(...)).

How to write your own async/awaitable coroutine function in Python?

£可爱£侵袭症+ 提交于 2019-12-23 20:20:55
问题 I'm trying to write my own awaiatbale function which could use in asyncio loop such as asyncio.sleep() method or something like these pre-awaitable implemented methods. Here is what I've done so far: import asyncio def coro1(): for i in range(1, 10): yield i def coro2(): for i in range(1, 10): yield i*10 class Coro: # Not used. def __await__(self): for i in range(1, 10): yield i * 100 @asyncio.coroutine def wrapper1(): return (yield from coro1()) @asyncio.coroutine def wrapper2(): return

NodeJS Async / Await - Build configuration file with API call

夙愿已清 提交于 2019-12-23 20:09:21
问题 I would like to have a configuration file with variables set with data I fetch from an API. I think I must use async and await features to do so, otherwise my variable would stay undefined. But I don't know how to integrate this and keep the node exports.myVariable = myData available within an async function ? Below is the code I tried to write to do so (all in the same file) : const fetchAPI = function(jsonQuery) { return new Promise(function (resolve, reject) { var reqOptions = { headers:

Is adding async to a method signature a breaking change?

断了今生、忘了曾经 提交于 2019-12-23 19:32:37
问题 In addressing a question about how much to use async/await, i.e. "should all methods return Task ?", the author of this answer, Matías Fidemraizer, claims that, even if your method currently only does synchronous stuff, it should still return a task so if you make it do async stuff later, "you can turn it into actual async operations without affecting the entire code base". That makes sense, but if I'm actually awaiting something, I have to add async to the method signature. So we're talking

Waiting for something to happen - asynchronous or synchronous model?

旧巷老猫 提交于 2019-12-23 18:24:21
问题 I have this method WaitForReaderArrival which is like below: (Runs all the time waiting for a reader to arrive) public void WaitForReaderArrival() { do { if (ReaderArrived()) { break; } System.Threading.Thread.Sleep(1000); } while (ReaderArrived() == false); } And I am awaiting for the reader to arrive using, await Task.Run(new Action(WaitForReaderArrival)); if (ReaderArrived()) { //Raise an ReaderArrived here! ..//blah blah } One of my co-worker asked me to change the above line just to

Difference between applying async-await at client and at service

本小妞迷上赌 提交于 2019-12-23 18:20:31
问题 I have created a WCF service and have its operationcontract and implementation like this: [OperationContract] Task<string> GetName(string name); public async Task<string> GetName(string name) { await Task.Delay(5000); var task1 = Task<string>.Factory.StartNew(() => { return "Your name is : " + name; }); var result = await task1; return result; } Now i am using this service at client side and created the client. ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();