async-await

Microsoft.Threading.Tasks.Extensions in Xamarin Mono projects

亡梦爱人 提交于 2020-01-11 11:53:55
问题 I have built a NuGet package for my Simple.OData.Client with support for Xamarin Android and iOS. This library uses Microsoft.Bcl.Async. Tests using Android and iOS simulator went OK, but when I install this new NuGet package into another project, it fails to compile Droid/Touch projects with the following message: C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(720,2): error : Exception while loading assemblies: System.IO.FileNotFoundException: Could not load

Thread control flow in async .NET Console program [duplicate]

有些话、适合烂在心里 提交于 2020-01-11 11:08:11
问题 This question already has an answer here : Async and await - difference between console, Windows Forms and ASP.NET (1 answer) Closed 9 months ago . I was messing around with async/await in C# just to dig into some of the thread control flow and stumbled upon an unusual behavior that I would really appreciate clarification on. It would make sense that the execution after await continues on a calling thread even if the Task itself was executed in background. And in fact that's exactly what

C# Asynchronous with task is slower than synchronous

回眸只為那壹抹淺笑 提交于 2020-01-11 09:59:01
问题 Do you know why sync fibonacci method is faster than async/await and that is faster than async task? I used async on every project method, so it's main this is so bad approach... Code: static int FibonacciSync(int number) { if (number == 0) { return 0; } else if (number == 1) { return 1; } else { var t1 = FibonacciSync(number - 1); var t2 = FibonacciSync(number - 2); return t1 + t2; } } async static Task<int> FibonacciAwait(int number) { if (number == 0) { return 0; } else if (number == 1) {

EF6 alpha Async Await on an Entity Stored Procedure / Function Import?

五迷三道 提交于 2020-01-11 05:38:09
问题 I'd like to apply the new async await functionality to Stored Procedures / Function Imports imported in my Entity model, but have as yet been unable to with the EF6 alpha. Is it yet possible in EF6 alpha2 (or the nightly build as of 20211) to call any of the new Async methods on an Entity Function Import (which calls a SQL Stored Procedure) that returns a collection of Complex Type? e.g. private async Task<IList<Company>> getInfo (string id) { using (CustomEntity context = new CustomEntity())

Does compiler perform “return value optimization” on chains of async methods

眉间皱痕 提交于 2020-01-11 05:12:26
问题 Not return value optimization in the traditional sense, but I was wondering when you have a situation like this: private async Task Method1() { await Method2(); } private async Task Method2() { await Method3(); } private async Task Method3() { //do something async } This could obviously be written more optimally: private Task Method1() { return Method2(); } private Task Method2() { return Method3(); } private async Task Method3() { //do something async } I just wondered whether anyone knew if

Does compiler perform “return value optimization” on chains of async methods

99封情书 提交于 2020-01-11 05:12:05
问题 Not return value optimization in the traditional sense, but I was wondering when you have a situation like this: private async Task Method1() { await Method2(); } private async Task Method2() { await Method3(); } private async Task Method3() { //do something async } This could obviously be written more optimally: private Task Method1() { return Method2(); } private Task Method2() { return Method3(); } private async Task Method3() { //do something async } I just wondered whether anyone knew if

Is it possible to resolve async function without return keyword

杀马特。学长 韩版系。学妹 提交于 2020-01-10 18:41:18
问题 I started to use ES7 feature async/await , which gives the best approach to deal with asynchronous tasks, and makes your code cleaner and readable. However it doesn't give you an access to Promise, created by async function, so if you do some async request in your async function you should promisify it, then await it and then return the result. I mean this: async function doStuff() { //stuff... var value = await new Promise(function(resolve) { $.get('http://some/url/...', function(result) { /

How can I Interleave / merge async iterables?

瘦欲@ 提交于 2020-01-10 17:52:07
问题 Suppose I have some asnyc iterable objects like this: // Promisified sleep function const sleep = ms => new Promise((resolve, reject) => { setTimeout(() => resolve(ms), ms); }); const a = { [Symbol.asyncIterator]: async function * () { yield 'a'; await sleep(1000); yield 'b'; await sleep(2000); yield 'c'; }, }; const b = { [Symbol.asyncIterator]: async function * () { await sleep(6000); yield 'i'; yield 'j'; await sleep(2000); yield 'k'; }, }; const c = { [Symbol.asyncIterator]: async

Not awaiting an async call is still async, right?

。_饼干妹妹 提交于 2020-01-10 17:45:33
问题 I'm sorry if this is a silly question (or a duplicate). I have a function A : public async Task<int> A(/* some parameters */) { var result = await SomeOtherFuncAsync(/* some other parameters */); return (result); } the I have another function B , calling A but not using the return value: public Task B(/* some parameters */) { var taskA = A(/* parameters */); // #1 return (taskA); } Note that B is not declared async and is not awaiting the call to A . The call to A is not a fire-and-forget

MVC4 + async/await + return response before action completes

℡╲_俬逩灬. 提交于 2020-01-10 07:45:08
问题 In my MVC4 app I need to add a controller for uploading and processing large files. Immediately after the file is uploaded I need to start async processing of that file and return response to the browser without waiting for the processing to complete. Obviously I could start a new thread for processing the file manually, but I'm wondering if I can implement this scenario using async/await mechanism introduced with .net 4.5 To test the concept I've tried something like this: public async Task