async-await

Awaited but never resolved/rejected promise memory usage [duplicate]

对着背影说爱祢 提交于 2019-12-21 06:47:16
问题 This question already has an answer here : Does never resolved promise cause memory leak? (1 answer) Closed last month . Will await ing a Promise which neither resolves nor rejects (never settle/unfulfilled) cause a memory leak? I got curious about this while looking at React hooks with slorber/awesome-debounce-promise that creates new promises, but only settles the last one of them, thus leaving many/most unsettle/unfulfilled. 回答1: Preface (you probably know this!): await is syntactic sugar

How to call an async method from a property setter

谁说我不能喝 提交于 2019-12-21 06:42:42
问题 Here is my problem: I have a WPF TextBox binded on the property Filter. It works as a filter: each time the TextBox.Text changes, the Filter property is set. <TextBox Text="{Binding Filter, UpdateSourceTrigger=PropertyChanged, Mode=OneWayToSource}" /> Now on the ViewModel there is my Filter property: each time the filter changes I update my values. private string _filter; public string Filter { get { return _filter; } set { _filter = value; // call to an async WEB API to get values from the

How to find out deadlocking awaited Tasks and their current call stack?

孤街醉人 提交于 2019-12-21 05:28:11
问题 Here is one simplified example I found that really hard to debug deadlock in awaited tasks in some cases: class Program { static void Main(string[] args) { var task = Hang(); task.Wait(); } static async Task Hang() { var tcs = new TaskCompletionSource<object>(); // do some more stuff. e.g. another await Task.FromResult(0); await tcs.Task; tcs.SetResult(0); } } This example is easy to understand why it deadlocks, it is awaiting a task which is finished later on. It looks stupid but similar

Async Await targeting 4.0 deployment requirements

耗尽温柔 提交于 2019-12-21 05:26:08
问题 Microsoft has updated the async/await targeting for .net 4.0 and now suggests using the Microsoft.Bcl.Async library available on nuget. In the release notes, it states that .net 4 with KB 2468871 is required. Is KB2468871 a build requirement or a deployment requirement? What aspect of KB2468871 makes it required? 回答1: Quoting from http://support.microsoft.com/kb/2468871/en-us Feature 5 Changes to the support portable libraries. These changes include API updates and binder modifications. This

How can I use async-await with MongoClient

爷,独闯天下 提交于 2019-12-21 05:24:18
问题 When I run this (using node v7.5.0 with --harmony): var MongoClient = require('mongodb').MongoClient, var url = "mongodb://localhost:27017/myDB"; var test = await MongoClient.connect(url); module.exports = test; I get this error: var test = await MongoClient.connect(url); ^^^^^^^^^^^ SyntaxError: Unexpected identifier MongoClient.connect(url) does return a promise What I ultimately want to achieve is to create a node module that will connect to a mondoDB and will be usable as in the following

using await Task.Delay in a for kills performance

蓝咒 提交于 2019-12-21 05:17:10
问题 Let's say I want to start roughly N tasks per second distributed equally. So I tried this: public async Task Generate(int numberOfCallsPerSecond) { var delay = TimeSpan.FromMiliseconds(1000/numberOfCallsPerSecond); // a call should happen every 1000 / numberOfCallsPerSecond miliseconds for (int i=0; i < numberOfcallsPerSecond; i++) { Task t = Call(); // don't wait for result here await Task.Delay(delay); } } At first I expected this to run in 1 second but for numberOfCallsPerSecond = 100 it

Is there a .NET 4.5 equivalent to: Storagefile.Openasync

北城余情 提交于 2019-12-21 05:14:12
问题 I'm falling in love with async and await, however I cannot figure out how to await a file open without using Task.Run. There seems to be an API in WRT. Where is the .NET 4.5 equivalent? I ask because if i'm accessing a UNC share on a remote machine this has the potential to block for a very long time if the machine is down or not responding to network requests for some reason. It seems like such a big over site. using (FileStream stream = await Task.Run(() => new FileStream(@"c:\temp\text.txt

async task cancellation c# xamarin

好久不见. 提交于 2019-12-21 04:31:29
问题 I have a functionality of search users. I have provided a textview and on that textview changed method I'm firing a method to get data from web server. But I'm facing problem when user types letter, because all the api hits done in async task. Service should be hit after 100 milli-sec of wait, means if user types a letter "a" then doesn't type for 100 milli-sec then We have to hit the service. But if user types "a" then "b" then "c", so one service should be hit for "abc", not for all. I

async task cancellation c# xamarin

流过昼夜 提交于 2019-12-21 04:31:16
问题 I have a functionality of search users. I have provided a textview and on that textview changed method I'm firing a method to get data from web server. But I'm facing problem when user types letter, because all the api hits done in async task. Service should be hit after 100 milli-sec of wait, means if user types a letter "a" then doesn't type for 100 milli-sec then We have to hit the service. But if user types "a" then "b" then "c", so one service should be hit for "abc", not for all. I

MVC4 WebApi process launcher

假装没事ソ 提交于 2019-12-21 04:30:13
问题 I have a MVC4 API REST trying to launch a process in a new thread. I am working with framework 4.5 and trying to use sync and await clausules. My code looks like: [AcceptVerbs("POST")] public HttpResponseMessage Launch(string id) { runProcessAsync(id); // 1 return Request.CreateResponse(HttpStatusCode.Accepted); // 2 } protected async void runProcessAsync(string id) { int exitcode = await runProcess(id); // 3 string exitcodesz = string.Format("exitcode: {0}", exitcode); // 4 // do more stuff