async-await

await Task.Delay(foo); takes seconds instead of ms

╄→гoц情女王★ 提交于 2020-12-29 04:20:25
问题 Using a variable delay in Task.Delay randomly takes seconds instead of milliseconds when combined with a IO-like operation. Code to reproduce: using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace ConsoleApplication { class Program { static void Main(string[] args) { Task[] wait = { new delayTest().looper(5250, 20), new delayTest().looper(3500, 30), new delayTest().looper

await Task.Delay(foo); takes seconds instead of ms

谁都会走 提交于 2020-12-29 04:19:48
问题 Using a variable delay in Task.Delay randomly takes seconds instead of milliseconds when combined with a IO-like operation. Code to reproduce: using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace ConsoleApplication { class Program { static void Main(string[] args) { Task[] wait = { new delayTest().looper(5250, 20), new delayTest().looper(3500, 30), new delayTest().looper

await Task.Delay(foo); takes seconds instead of ms

99封情书 提交于 2020-12-29 04:19:22
问题 Using a variable delay in Task.Delay randomly takes seconds instead of milliseconds when combined with a IO-like operation. Code to reproduce: using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace ConsoleApplication { class Program { static void Main(string[] args) { Task[] wait = { new delayTest().looper(5250, 20), new delayTest().looper(3500, 30), new delayTest().looper

Node repl with async await

不羁岁月 提交于 2020-12-29 02:42:46
问题 I would like to add support to async/await to node repl Following this issue: https://github.com/nodejs/node/issues/8382 I've tried to use this one https://github.com/paulserraino/babel-repl but it is missing async await suppport I would like to use this snippet const awaitMatcher = /^(?:\s*(?:(?:let|var|const)\s)?\s*([^=]+)=\s*|^\s*)(await\s[\s\S]*)/; const asyncWrapper = (code, binder) => { let assign = binder ? `root.${binder} = ` : ''; return `(function(){ async function _wrap() { return

TaskCompletionSource : When to use SetResult() versus TrySetResult(), etc

假装没事ソ 提交于 2020-12-29 01:47:43
问题 I'm trying to wrap my head around the TPL, the new async / await features in C# 5, and the mysteries of TaskCompletionSource . One thing that isn't clear to me is when to use SetResult , SetException , and SetCancel versus TrySetResult , TrySetException and TrySetCancel . This is what MSDN has to say: This operation will return false if the Task is already in one of the three final states: RanToCompletion, Faulted, or Canceled. This method also returns false if the underlying Task has already

TaskCompletionSource : When to use SetResult() versus TrySetResult(), etc

北城余情 提交于 2020-12-29 01:42:40
问题 I'm trying to wrap my head around the TPL, the new async / await features in C# 5, and the mysteries of TaskCompletionSource . One thing that isn't clear to me is when to use SetResult , SetException , and SetCancel versus TrySetResult , TrySetException and TrySetCancel . This is what MSDN has to say: This operation will return false if the Task is already in one of the three final states: RanToCompletion, Faulted, or Canceled. This method also returns false if the underlying Task has already

Is this the proper/safe way to create a ShowDialogAsync extension method on `Window`? [closed]

流过昼夜 提交于 2020-12-27 07:18:27
问题 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 3 hours ago . Improve this question I had a need to call ShowDialog on a Window , but had to do so in a non-blocking way. This is the solution I came up with. I'm wondering if this violates any principles around Async / Await or if there is anything that I'm not seeing with this design. public

HttpResponseMessage' does not contain a definition for 'GetAwaiter' and no accessible extension method 'GetAwaiter'

浪尽此生 提交于 2020-12-27 07:15:56
问题 I have this xUnit method in C# which test a web api [Fact] public async Task GetWeatherForecast() { var apiClient = new HttpClient(); var apiResponse = await apiClient.GetAsync($"http://xxx/weatherforecast").Result; Assert.True(apiResponse.IsSuccessStatusCode); } But hit this error HttpResponseMessage' does not contain a definition for 'GetAwaiter' and no accessible extension method 'GetAwaiter' . If I removed async Task and await , it could run successfully. 回答1: Don't call Result , it's

HttpResponseMessage' does not contain a definition for 'GetAwaiter' and no accessible extension method 'GetAwaiter'

生来就可爱ヽ(ⅴ<●) 提交于 2020-12-27 07:15:41
问题 I have this xUnit method in C# which test a web api [Fact] public async Task GetWeatherForecast() { var apiClient = new HttpClient(); var apiResponse = await apiClient.GetAsync($"http://xxx/weatherforecast").Result; Assert.True(apiResponse.IsSuccessStatusCode); } But hit this error HttpResponseMessage' does not contain a definition for 'GetAwaiter' and no accessible extension method 'GetAwaiter' . If I removed async Task and await , it could run successfully. 回答1: Don't call Result , it's

HttpResponseMessage' does not contain a definition for 'GetAwaiter' and no accessible extension method 'GetAwaiter'

假如想象 提交于 2020-12-27 07:14:36
问题 I have this xUnit method in C# which test a web api [Fact] public async Task GetWeatherForecast() { var apiClient = new HttpClient(); var apiResponse = await apiClient.GetAsync($"http://xxx/weatherforecast").Result; Assert.True(apiResponse.IsSuccessStatusCode); } But hit this error HttpResponseMessage' does not contain a definition for 'GetAwaiter' and no accessible extension method 'GetAwaiter' . If I removed async Task and await , it could run successfully. 回答1: Don't call Result , it's