async-await

API request WaitingForActivation “Not yet computed” error

老子叫甜甜 提交于 2019-12-20 16:32:49
问题 I'm using the Poloniex C# API code from: https://github.com/Jojatekok/PoloniexApi.Net On my console application the request to get balances is working, i make the API call and the balances come back, but on my Windows Forms application it's not getting past waiting for the balances: Id = 14, Status = WaitingForActivation, Method = "{null}", Result = "{Not yet computed}" when using this code: PoloniexClient polo_client { get; set; } private void Main(){ polo_client = new PoloniexClient(ApiKeys

API request WaitingForActivation “Not yet computed” error

≡放荡痞女 提交于 2019-12-20 16:32:03
问题 I'm using the Poloniex C# API code from: https://github.com/Jojatekok/PoloniexApi.Net On my console application the request to get balances is working, i make the API call and the balances come back, but on my Windows Forms application it's not getting past waiting for the balances: Id = 14, Status = WaitingForActivation, Method = "{null}", Result = "{Not yet computed}" when using this code: PoloniexClient polo_client { get; set; } private void Main(){ polo_client = new PoloniexClient(ApiKeys

Async and Await in ApiController Post

两盒软妹~` 提交于 2019-12-20 12:35:22
问题 I'm still not quite clear about async and await in .net 4.5. So far, I think I understand that await: puts the function (to its right) on a separate thread. puts the execution back to the current function's caller but holds the rest of the current function's code "hostage" until the awaiting (async) function is finished. Please correct me if I'm misunderstanding something. So, if the above is true, I'm stuck with an ApiController's Post function that I want async: [HttpPost] public async Task

How to transform task.Wait(CancellationToken) to an await statement?

牧云@^-^@ 提交于 2019-12-20 12:16:12
问题 So, task.Wait() can be transformed to await task . The semantics are different, of course, but this is roughly how I would go about transforming a blocking code with Waits to an asynchronous code with awaits . My question is how to transform task.Wait(CancellationToken) to the respective await statement? 回答1: To create a new Task that represents an existing task but with an additional cancellation token is quite straightforward. You only need to call ContinueWith on the task, use the new

Does SemaphoreSlim (.NET) prevent same thread from entering block?

自古美人都是妖i 提交于 2019-12-20 12:04:13
问题 I have read the docs for SemaphoreSlim SemaphoreSlim MSDN which indicates that the SemaphoreSlim will limit a section of code to be run by only 1 thread at a time if you configure it as: SemaphoreSlim _semaphoreSlim = new SemaphoreSlim(1, 1); However, it doesn't indicate if it stops the same thread from accessing that code. This comes up with async and await. If one uses await in a method, control leaves that method and returns when whatever task or thread has completed. In my example, I use

Typescript async/await and angular $q service

别来无恙 提交于 2019-12-20 11:43:08
问题 New TypeScript async/await feature uses ES6 promises. AngularJS uses $q service promises with slightly different interface. Is there any way to use TypeScript async/await feature with $q service promises? 回答1: You can make it work like this: angular.module('your app') .run(['$window', '$q', function($window, $q) { $window.Promise = $q; }]); 回答2: I do not think you will be able to use them directly. But it should be quite easy to convert q promise into a++ promise, something like this:

Why is Enumerator.MoveNext not working as I expect it when used with using and async-await?

℡╲_俬逩灬. 提交于 2019-12-20 11:21:53
问题 I would like to enumerate through a List<int> and call a async method. If I do this in this way: public async Task NotWorking() { var list = new List<int> {1, 2, 3}; using (var enumerator = list.GetEnumerator()) { Trace.WriteLine(enumerator.MoveNext()); Trace.WriteLine(enumerator.Current); await Task.Delay(100); } } the result is: True 0 but I expect it to be: True 1 If i remove the using or the await Task.Delay(100) : public void Working1() { var list = new List<int> {1, 2, 3}; using (var

Lazy shared async resource — Clarification?

风流意气都作罢 提交于 2019-12-20 10:47:16
问题 I saw this example at the end of Stephen's book. This code can be accessed by more than one thread. static int _simpleValue; static readonly Lazy<Task<int>> MySharedAsyncInteger = new Lazy<Task<int>>( async () => { await Task.Delay(TimeSpan.FromSeconds(2)).ConfigureAwait(false); return _simpleValue++; }); async Task GetSharedIntegerAsync() { int sharedValue = await MySharedAsyncInteger.Value; } No matter how many parts of the code call Value simultaneously, the Task<int> is only created once

Calling async method in IEnumerable.Select

牧云@^-^@ 提交于 2019-12-20 10:17:57
问题 I have the following code, converting items between the types R and L using an async method: class MyClass<R,L> { public async Task<bool> MyMethodAsync(List<R> remoteItems) { ... List<L> mappedItems = new List<L>(); foreach (var remoteItem in remoteItems ) { mappedItems.Add(await MapToLocalObject(remoteItem)); } //Do stuff with mapped items ... } private async Task<L> MapToLocalObject(R remoteObject); } Is this possible to write using an IEnumerable.Select call (or similar) to reduce lines of

How should we use async await? [duplicate]

旧城冷巷雨未停 提交于 2019-12-20 10:16:54
问题 This question already has answers here : What is the purpose of “return await” in C#? (7 answers) How and when to use ‘async’ and ‘await’ (21 answers) Closed 7 months ago . I was looking at how to use async await, but I do not quite get it when we have multiple methods invoking each other. Should we always use await or should we only use await when we are actually ready to use the result? So for example should we do it like this: async Task<string[]> FooAsync() { var info = await Func1();