async-await

Enable Async TransactionScope without TransactionScopeAsyncFlowOption.Enabled

╄→гoц情女王★ 提交于 2020-02-04 04:39:14
问题 Following is Async Cache and Database update using Transaction Scope. I cannot use TransactionScopeAsyncFlowOption.Enabled introduced in the v 4.5.1, since the Apache Ignite.Net Cache I am using doesn't support it. I have tried finding a workaround by capturing the current Synchronization Context and then explicitly using Synchronization Context Send method to complete the transaction, but this doesn't work as I still get an error Transaction scope must be disposed on same thread it was

Parallel ForEach not awaiting for HttpClient [duplicate]

孤街浪徒 提交于 2020-02-03 01:27:25
问题 This question already has answers here : Passing async method into Parallel.ForEach (3 answers) Parallel foreach with asynchronous lambda (5 answers) parallel.foreach and httpclient - strange behaviour (2 answers) Closed last month . In the code below (a fairly simple one just for demonstration), my finally clause gets executed when awaiting for the HttpClient to finish. So the output is something like: Done StatusCode: 200,... When I was expecting it to be: StatusCode: 200,... Done class

Using async/await to get data from a callback and return a value only after a promise is resolved

蓝咒 提交于 2020-02-01 03:27:31
问题 I'm trying to use async/await but I think I'm misunderstanding something critically. As basically as possible, I am trying to calculate the distance between a list of locations and one designated location using google maps api. Here is a rough example of what I'm trying to do: https://jsfiddle.net/qu5y69rj/1/ You can see that the result of that function is undefined 3 times instead of what I would expect which would be {distance: "ZERO_RESULTS"} for each call in the case of my contrived

Using async/await to get data from a callback and return a value only after a promise is resolved

你离开我真会死。 提交于 2020-02-01 03:27:07
问题 I'm trying to use async/await but I think I'm misunderstanding something critically. As basically as possible, I am trying to calculate the distance between a list of locations and one designated location using google maps api. Here is a rough example of what I'm trying to do: https://jsfiddle.net/qu5y69rj/1/ You can see that the result of that function is undefined 3 times instead of what I would expect which would be {distance: "ZERO_RESULTS"} for each call in the case of my contrived

Windows Service running Async code not waiting on work to complete

五迷三道 提交于 2020-01-31 08:40:27
问题 In Brief I have a Windows Service that executes several jobs as async Tasks in parallel. However, when the OnStop is called, it seems that these are all immediately terminated instead of being allowed to stop in a more gracious manner. In more detail Each job represents an iteration of work, so having completed its work the job then needs to run again. To accomplish this, I am writing a proof-of-concept Windows Service that: runs each job as an awaited async TPL Task (these are all I/O bound

Difference between passing a regular and async anonymous function to Task.Run for asynchronous work

给你一囗甜甜゛ 提交于 2020-01-30 10:53:28
问题 What is the difference between ResultType result = await Task.Run(() => GetResultAsync()) and ResultType result = await Task.Run(async() => await GetResultAsync()) I would speculate that the former would fire and forget GetResultAsync() , since it is not awaited, but then how does it get the result? I am surprised that the return type of the former Task.Run is Task<ResultType> and not Task<Task<ResultType>> . 回答1: Both do the same from perspective of result. In both cases the overload Task

Difference between passing a regular and async anonymous function to Task.Run for asynchronous work

筅森魡賤 提交于 2020-01-30 10:50:16
问题 What is the difference between ResultType result = await Task.Run(() => GetResultAsync()) and ResultType result = await Task.Run(async() => await GetResultAsync()) I would speculate that the former would fire and forget GetResultAsync() , since it is not awaited, but then how does it get the result? I am surprised that the return type of the former Task.Run is Task<ResultType> and not Task<Task<ResultType>> . 回答1: Both do the same from perspective of result. In both cases the overload Task

Difference between passing a regular and async anonymous function to Task.Run for asynchronous work

时光怂恿深爱的人放手 提交于 2020-01-30 10:50:14
问题 What is the difference between ResultType result = await Task.Run(() => GetResultAsync()) and ResultType result = await Task.Run(async() => await GetResultAsync()) I would speculate that the former would fire and forget GetResultAsync() , since it is not awaited, but then how does it get the result? I am surprised that the return type of the former Task.Run is Task<ResultType> and not Task<Task<ResultType>> . 回答1: Both do the same from perspective of result. In both cases the overload Task

Is there a way to wait until a function is finished?

*爱你&永不变心* 提交于 2020-01-30 09:41:28
问题 I'm trying to get information (true/false) from AsyncStorage in a function and create a string which is importent to fetch data in the next step. My problem is, the function is not finished until the string is required. I tried many solutions from the internet like async function and await getItem or .done() or .then(), but none worked out for me. The current behaviour is that the console displays first "channel required: " than "channel: channel_id0". 回答1: Aspects in your question are

Setting up a C# Test with Moq against Async methods

感情迁移 提交于 2020-01-30 08:17:08
问题 I'm trying to create a set of test methods using Moq to cover the external dependencies. These dependencies are async in nature and I have come across a set of them that when awaited they never return, so I'm not sure what I'm missing. The test itself is very simple. [TestMethod] public async Task UpdateItemAsync() { var repository = GetRepository(); var result = await repository.UpdateItemAsync("", new object()); Assert.IsNotNull(result); } The GetRepository method above is what sets up the