async-await

StackExchange.Redis Deadlocking

混江龙づ霸主 提交于 2019-12-30 08:34:12
问题 I'm using StackExchange.Redis (SE.R henceforth) in my Nancy application. There is a single global ConnectionMultiplexer that gets automatically passed around by Nancy's TinyIoC via constructor parameters, and any time I try and use GetDatabase and one of the *Async methods (sync methods only start failing after one of the async methods have been attempted) my application deadlocks. Looking at my parallel stacks it appears that I have four threads: The thread that called Result on one of my

Does await await promise-like objects? [duplicate]

Deadly 提交于 2019-12-30 08:33:22
问题 This question already has an answer here : What should happen with `await` when the expression after the keyword does not evaluate to promise? (1 answer) Closed 2 years ago . According to Mozilla, await only awaits Promises: [rv] Returns the resolved value of the promise, or the value itself if it's not a Promise. If you await a non-Promise, a resolved promise will be immediately returned, and it will not await. However, the following code awaits without using Promises in Chrome & FF. var obj

Task.Yield() versus Task.Delay(0)

本小妞迷上赌 提交于 2019-12-30 08:06:26
问题 Does Delay(0) always get inlined? In my experience, it does: using System; using System.Threading; using System.Threading.Tasks; namespace ConsoleApplication { class Program { static async Task Test() { await Task.Yield(); Console.WriteLine("after Yield(), thread: {0}", Thread.CurrentThread.ManagedThreadId); await Task.Delay(0); Console.WriteLine("after Delay(0), thread: {0}", Thread.CurrentThread.ManagedThreadId); await Task.Delay(100); Console.WriteLine("after Delay(100), thread: {0}",

Paralell.ForEach with HttpClient and ContinueWith

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-30 06:56:18
问题 I have a method that attempts to download data from several URLs in Parallel, and return an IEnumerable of Deserialized types The method looks like this: public IEnumerable<TContent> DownloadContentFromUrls(IEnumerable<string> urls) { var list = new List<TContent>(); Parallel.ForEach(urls, url => { lock (list) { _httpClient.GetAsync(url).ContinueWith(request => { var response = request.Result; //todo ensure success? response.Content.ReadAsStringAsync().ContinueWith(text => { var results =

Difference between await for and listen in Dart

纵然是瞬间 提交于 2019-12-30 06:21:40
问题 I am trying to create a web server stream. Here is the code: import 'dart:io'; main() async { HttpServer requestServer = await HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, 8000); requestServer.listen((request) { //comment out this or the await for to work request.response ..write("This is a listen stream") ..close(); }); await for (HttpRequest request in requestServer) { request.response ..write("This is an await for stream") ..close(); } } What is the difference between listen and await

Difference between await for and listen in Dart

时光怂恿深爱的人放手 提交于 2019-12-30 06:21:08
问题 I am trying to create a web server stream. Here is the code: import 'dart:io'; main() async { HttpServer requestServer = await HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, 8000); requestServer.listen((request) { //comment out this or the await for to work request.response ..write("This is a listen stream") ..close(); }); await for (HttpRequest request in requestServer) { request.response ..write("This is an await for stream") ..close(); } } What is the difference between listen and await

Should I call ConfigureAwait(false) on every awaited operation

旧时模样 提交于 2019-12-30 05:44:28
问题 I read this article https://blog.stephencleary.com/2012/07/dont-block-on-async-code.html - however I'm seeing a contradiction: I'm aware of the problem of deadlocking the UI thread because the UI thread blocks waiting for an async operation to complete, but the same async operation is synchronized to the UI thread context - consequently the async operation cannot enter the UI thread, so the UI thread won't stop waiting. The article tells us the workaround is to not block on the UI thread,

What is the reason behind CS1998 “method lacks await operators”

我与影子孤独终老i 提交于 2019-12-30 04:17:06
问题 The C# compiler generates a CS1998 warning when an async method lacks any await operators. What are the reasons behind the warning? I know that async introduces overhead in the method by adding a statemachine and exception handling. Is the primary reason for the warning performance ? Or is the reason to notify me that I might have forgotten an await somewhere? Maybe someone from the language design team can shed some light on this one... :) (Please: do not post answers that say 'you can

C# async await using LINQ ForEach()

不羁岁月 提交于 2019-12-30 03:55:09
问题 I have the following code that correctly uses async/await paradigm. internal static async Task AddReferencseData(ConfigurationDbContext context) { foreach (var sinkName in RequiredSinkTypeList) { var sinkType = new SinkType() { Name = sinkName }; context.SinkTypeCollection.Add(sinkType); await context.SaveChangesAsync().ConfigureAwait(false); } } What is the equivalent way to write this if, instead of using foreach(), I want to use LINQ ForEach()? This one, for example, gives compile error.

async await in image loading

。_饼干妹妹 提交于 2019-12-30 02:45:15
问题 Temp.js export default class Temp { async addImageProcess(src){ let img = new Image(); img.src = src; return img.onload = await function(){ return this.height; } } } anotherfile.js import Temp from '../../classes/Temp' let tmp = new Temp() imageUrl ="https://www.google.co.in/images/branding/googlelogo/2x/googlelogo_color_120x44dp.png" let image = tmp.addImageProcess(imageUrl); console.log(image) Above is my code. I have a image url and tried to get image's properties using async await but it