Running multiple async tasks and waiting for them all to complete

I need to run multiple async tasks in a console application, and wait for them all to complete before further processing. There’s many articles out there, but I seem to get more confused the more I read. I’ve read and understand the basic principles of the Task library, but I’m clearly missing a link somewhere. … Read more

HttpClient.GetAsync(…) never returns when using await/async

Edit: This question looks like it might be the same problem, but has no responses… Edit: In test case 5 the task appears to be stuck in WaitingForActivation state. I’ve encountered some odd behaviour using the System.Net.Http.HttpClient in .NET 4.5 – where “awaiting” the result of a call to (e.g.) httpClient.GetAsync(…) will never return. This … Read more

How can I limit Parallel.ForEach?

I have a Parallel.ForEach() async loop with which I download some webpages. My bandwidth is limited so I can download only x pages per time but Parallel.ForEach executes whole list of desired webpages. Is there a way to limit thread number or any other limiter while running Parallel.ForEach? Demo code: Parallel.ForEach(listOfWebpages, webpage => { Download(webpage); … Read more

What is the difference between asynchronous programming and multithreading?

I thought that they were basically the same thing — writing programs that split tasks between processors (on machines that have 2+ processors). Then I’m reading this, which says: Async methods are intended to be non-blocking operations. An await expression in an async method doesn’t block the current thread while the awaited task is running. … Read more

When correctly use Task.Run and when just async-await

I would like to ask you on your opinion about the correct architecture when to use Task.Run. I am experiencing laggy UI in our WPF .NET 4.5 application (with Caliburn Micro framework). Basically I am doing (very simplified code snippets): public class PageViewModel : IHandle<SomeMessage> { … public async void Handle(SomeMessage message) { ShowLoadingAnimation(); // … Read more

How to reject in async/await syntax?

How can I reject a promise that returned by an async/await function? e.g. Originally: foo(id: string): Promise<A> { return new Promise((resolve, reject) => { someAsyncPromise().then((value)=>resolve(200)).catch((err)=>reject(400)) }); } Translate into async/await: async foo(id: string): Promise<A> { try{ await someAsyncPromise(); return 200; } catch(error) {//here goes if someAsyncPromise() rejected} return 400; //this will result in a resolved … Read more

asynchronous and non-blocking calls? also between blocking and synchronous

What is the difference between asynchronous and non-blocking calls? Also between blocking and synchronous calls (with examples please)? 14 Answers 14 In many circumstances they are different names for the same thing, but in some contexts they are quite different. So it depends. Terminology is not applied in a totally consistent way across the whole … Read more

AngularJS : Initialize service with asynchronous data

I have an AngularJS service that I want to initialize with some asynchronous data. Something like this: myModule.service(‘MyService’, function($http) { var myData = null; $http.get(‘data.json’).success(function (data) { myData = data; }); return { setData: function (data) { myData = data; }, doStuff: function () { return myData.getSomeData(); } }; }); Obviously this won’t work because … Read more