async-await

Exception handling inside “async void” WPF command handlers

♀尐吖头ヾ 提交于 2019-12-18 05:52:38
问题 I'm reviewing some WPF code of my colleagues, which is a library of UserControl -based components with a lot of async void event and command handlers. These methods currently do not implement any error handling internally. The code in a nutshell: <Window.CommandBindings> <CommandBinding Command="ApplicationCommands.New" Executed="NewCommand_Executed"/> </Window.CommandBindings> private async void NewCommand_Executed(object sender, ExecutedRoutedEventArgs e) { // do some fake async work (and

UOW - A second operation started on this context before a previous asynchronous operation completed

偶尔善良 提交于 2019-12-18 05:43:45
问题 I am trying following code, it has two parts, one is navigation via prism. When navigation is allowed I am starting a deep load asynchronously but each time with a new context. In later code I would want to cancel pending navigations that are not finished this loading but the below code does not even work so cancellation is a matter for later ;-) navigation logic : no problems here public void OnNavigatedTo(NavigationContext navigationContext) { int relatieId = (int)navigationContext

need a correct eslintrc for async/await - using 7.6+ nodejs

浪尽此生 提交于 2019-12-18 05:39:10
问题 With the latest version of nodejs 7.6+ I started using async/await. I was using jshint but from what I read they currently do support this syntax and some suggested using eslint. So ok I set eslint up but argh.. it flags async functions too. Parsing error: Unexpected token init (Fatal) I know there is nothing wrong as my code is running fine it's just the linter. Too if I comment out an async function it just flags the next one. IN fact eslint only flags the first async found with this error

How to cancel and raise an exception on Task.WhenAll if any exception is raised?

懵懂的女人 提交于 2019-12-18 05:12:43
问题 I am waiting on multiples task using Task.WhenAll. When one of them generates an exception I would like Task.WhenAll (or any other way of awaiting multiples tasks) to immediately cancel the others tasks and raise an exception. Is it possible? Thanks in advance 回答1: Cancellation is coopertive the WhenAll can't cancel the threads but you can pass all of them a CancellationToken and fire the token when you get a exception. CancellationTokenSource cts = new CancellationTokenSource(); var task1 =

Return to View with Async Await

若如初见. 提交于 2019-12-18 05:04:18
问题 I have a process I would like to run in the background. This is executed with a click of an action link. Action to call: public async Task<ActionResult> ProcessRec() { await Task.Run(() => waitTimer()); return RedirectToAction("Index", "Home"); } public void waitTimer() { Thread.Sleep(10000); } This however waits for the full 10 seconds before redirecting me to my "Index, Home" action. I am very new to Await/Async so I know I am interpreting something wrong here. How do I get the application

Parallel Blob Upload throwing 404 Bad Request intermittently

允我心安 提交于 2019-12-18 04:53:06
问题 I have a very simple service, public class AzureService : IAzureService { private readonly CloudBlobContainer _container; public AzureService(ISettings settings) { var storageAccount = CloudStorageAccount.Parse(settings.BlobConnectionString); var blobClient = storageAccount.CreateCloudBlobClient(); _container = blobClient.GetContainerReference(settings.BlobContainerName); } public Task UploadBlobAsync(string fileName, Stream stream) { var blob = _container.GetBlockBlobReference(fileName);

What is the point of having async Main?

杀马特。学长 韩版系。学妹 提交于 2019-12-18 04:39:23
问题 As we know, C#7 allows to make Main() function asynchronous. What advantages it gives? For what purpose may you use async Main instead of a normal one? 回答1: It's actually C# 7.1 that introduces async main. The purpose of it is for situations where you Main method calls one or more async methods directly. Prior to C# 7.1, you had to introduce a degree of ceremony to that main method, such as having to invoke those async methods via SomeAsyncMethiod().GetAwaiter().GetResult() . By being able to

Try Catch outside of: await Task.Run(()

有些话、适合烂在心里 提交于 2019-12-18 04:38:12
问题 Does try catch outside of: await Task.Run(() => make sense or just use them only inside of await? private async void Test() { try { await Task.Run(() => { try { DoingSomething(); } catch (Exception ex) { log.Error(ex.Message); } }); } catch (Exception ex) { log.Error(ex.Message); } } 回答1: If you handle Exception inside the delegate (in your case just for logging purpose), await will not raise an exception in normal circumstances. This should be fine. private async Task Test() { await Task.Run

How to await and return the result of a http.request(), so that multiple requests run serially?

点点圈 提交于 2019-12-18 04:35:09
问题 Assume there is a function doRequest(options) , which is supposed to perform an HTTP request and uses http.request() for that. If doRequest() is called in a loop, I want that the next request is made after the previous finished (serial execution, one after another). In order to not mess with callbacks and Promises, I want to use the async/await pattern (transpiled with Babel.js to run with Node 6+). However, it is unclear to me, how to wait for the response object for further processing and

Using async/await in node 7.4

左心房为你撑大大i 提交于 2019-12-18 04:34:17
问题 I thought async/await was supported in node 7.4, however this example does not work: const Promise = require('bluebird'); async function main(){ await Promise.delay(1000) } main(); Results in: async function main(){ ^^^^^^^^ SyntaxError: Unexpected token function How can I use async/await with node 7.4? 回答1: Yes async-await is supported in Node.js v7 but its locked behind the harmony flag. Features which are not yet production ready are behind this flag. To use async-await in Node.js v7