async-await

async/await - am I using the wrong synchronisation context?

折月煮酒 提交于 2020-01-04 15:26:32
问题 Apparently i did not understand async/await yet and the following basic example already causes some headache: For test purposes i create a Window which represents my UI for now and i want to fire an asynchronous method which does some work in the background when the window opens. I added a Listview to my window to test if the UI is responding. When i execute the following code, two things happen that i do not understand: My ListView shows the CustomObjects that i define in the constructor.

Closing WCF Service from Async method?

冷暖自知 提交于 2020-01-04 14:16:30
问题 I have a service layer project on an MVC 5 ASP.NET application I am creating on .NET 4.5.2 which calls out to an External 3rd Party WCF Service to Get Information asynchronously. An original method to call external service was as below (there are 3 of these all similar in total which I call in order from my GetInfoFromExternalService method (note it isnt actually called that - just naming it for illustration) private async Task<string> GetTokenIdForCarsAsync(Car[] cars) { try { if (

Writing async/await version of a promise

你。 提交于 2020-01-04 11:56:42
问题 The code below logs 'hello world' once in a second as expected. function moveOneStep() { return new Promise((res, rej) => { setTimeout(() => { res(console.log('Hello world!')) }, 1000) }) } async function main() { await moveOneStep(); await moveOneStep(); await moveOneStep(); await moveOneStep(); } Considering the return value of an async function corresponds to what is returned from resolve function in promises, why doesn't the code below output the same result, but instead logs all the

Writing async/await version of a promise

ぐ巨炮叔叔 提交于 2020-01-04 11:55:33
问题 The code below logs 'hello world' once in a second as expected. function moveOneStep() { return new Promise((res, rej) => { setTimeout(() => { res(console.log('Hello world!')) }, 1000) }) } async function main() { await moveOneStep(); await moveOneStep(); await moveOneStep(); await moveOneStep(); } Considering the return value of an async function corresponds to what is returned from resolve function in promises, why doesn't the code below output the same result, but instead logs all the

Rewriting code to take advantage of C# async feature

懵懂的女人 提交于 2020-01-04 09:18:45
问题 How to transform such code: public void Do2() { Console.WriteLine("Do2::Before"); Latent(() => Console.WriteLine("Do2::After")); } public void Latent(Action a) { registeredActions.Add(a); } public void TriggerActions() { foreach (Action a in registeredActions) { a(); } } To be usable like this: public async void Do1() { Console.WriteLine("Do1::Before"); await Latent(); Console.WriteLine("Do1::After"); } Note that I do not want Tasks to be executed on ThreadPool or on other threads or

AWS S3 GetObjectAsync Hangs/Times Out

自古美人都是妖i 提交于 2020-01-04 07:03:12
问题 Note: Answering my own question to help others in the future. I'm following the official documentation to get a text file from an S3 bucket and it hangs: static async Task ReadObjectDataAsync() { string responseBody = ""; try { GetObjectRequest request = new GetObjectRequest { BucketName = bucketName, Key = keyName }; //THIS NEXT LINE HANGS!!!! using (GetObjectResponse response = await client.GetObjectAsync(request)) using (Stream responseStream = response.ResponseStream) using (StreamReader

AWS S3 GetObjectAsync Hangs/Times Out

与世无争的帅哥 提交于 2020-01-04 07:02:53
问题 Note: Answering my own question to help others in the future. I'm following the official documentation to get a text file from an S3 bucket and it hangs: static async Task ReadObjectDataAsync() { string responseBody = ""; try { GetObjectRequest request = new GetObjectRequest { BucketName = bucketName, Key = keyName }; //THIS NEXT LINE HANGS!!!! using (GetObjectResponse response = await client.GetObjectAsync(request)) using (Stream responseStream = response.ResponseStream) using (StreamReader

Async await usage and overhead [closed]

元气小坏坏 提交于 2020-01-04 06:53:28
问题 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 years ago . I have a web api 2 endpoint that talks to a service class. The service class makes calls to Entity Framework (v6) I have applied async await on the methods where im writing to the database, querying etc.. using SaveChangesAsync(), etc My question is regarding the overhead.. the

Async await usage and overhead [closed]

余生长醉 提交于 2020-01-04 06:53:12
问题 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 years ago . I have a web api 2 endpoint that talks to a service class. The service class makes calls to Entity Framework (v6) I have applied async await on the methods where im writing to the database, querying etc.. using SaveChangesAsync(), etc My question is regarding the overhead.. the

Promise to async await when polling

夙愿已清 提交于 2020-01-04 06:37:05
问题 I'm trying to convert a function that uses promise (and polling) to an async function, but I'm not really sure how it works. I have this: function myFunction() { return new Promise(resolve => { // stuff here ... var poll = setInterval(function() { if (condition) { clearInterval(poll); resolve("done"); } }, 100); }); } .. but I'm unsure what to await here: async function myFunction() { // stuff here ... var poll = setInterval(function() { if (condition) { clearInterval(poll); // await what? }