async-await

Can SSIS jobs be async?

无人久伴 提交于 2020-08-08 02:08:22
问题 I'm a bit confused on whether the async methods work properly with an SSIS job or not. The Script Task items create a visual studio project that targets .NET Framework 4.5, with an output type of Class Library. If I make the main method public async void Main() and inside it do await calls against async methods, is it really waiting? Some of the posts I've seen here imply it does, and others imply it does not. 回答1: Unfortunately, SSIS Framework and base .Net classes were created well before

Do async methods throw exceptions on call or on await?

江枫思渺然 提交于 2020-08-07 05:13:57
问题 When I call an async method and get a task back, will that immediately throw or will it wait until I await the task? In other words, will this code work? Or will I have to wrap the method call in the try-block as well? Task task = ThisMethodWillThrow(); try { await task; } catch (Exception e) { Console.WriteLine("oops"); } 回答1: Both are possible. If the method is actually async (i.e. uses the C# async keyword in the declaration), then the C# compiler wraps it up in such a way that it will

Do async methods throw exceptions on call or on await?

允我心安 提交于 2020-08-07 05:12:46
问题 When I call an async method and get a task back, will that immediately throw or will it wait until I await the task? In other words, will this code work? Or will I have to wrap the method call in the try-block as well? Task task = ThisMethodWillThrow(); try { await task; } catch (Exception e) { Console.WriteLine("oops"); } 回答1: Both are possible. If the method is actually async (i.e. uses the C# async keyword in the declaration), then the C# compiler wraps it up in such a way that it will

Do async methods throw exceptions on call or on await?

点点圈 提交于 2020-08-07 05:12:31
问题 When I call an async method and get a task back, will that immediately throw or will it wait until I await the task? In other words, will this code work? Or will I have to wrap the method call in the try-block as well? Task task = ThisMethodWillThrow(); try { await task; } catch (Exception e) { Console.WriteLine("oops"); } 回答1: Both are possible. If the method is actually async (i.e. uses the C# async keyword in the declaration), then the C# compiler wraps it up in such a way that it will

Is there a difference between calling .Result or await on known completed tasks? [duplicate]

旧街凉风 提交于 2020-08-06 13:13:11
问题 This question already has answers here : Await on a completed task same as task.Result? (2 answers) Closed 5 years ago . Is there any functional, performance, or risk of deadlock difference in the below code blocks? Example 1: await Task.WhenAll(task1, task2); var result1 = await task1; var result2 = await task2; Example 2: await Task.WhenAll(task1, task2); var result1 = task1.Result; var result2 = task2.Result; 回答1: Is there any functional, performance, or risk of deadlock difference in the

Is there a difference between calling .Result or await on known completed tasks? [duplicate]

坚强是说给别人听的谎言 提交于 2020-08-06 13:13:00
问题 This question already has answers here : Await on a completed task same as task.Result? (2 answers) Closed 5 years ago . Is there any functional, performance, or risk of deadlock difference in the below code blocks? Example 1: await Task.WhenAll(task1, task2); var result1 = await task1; var result2 = await task2; Example 2: await Task.WhenAll(task1, task2); var result1 = task1.Result; var result2 = task2.Result; 回答1: Is there any functional, performance, or risk of deadlock difference in the

async / await fetch in node-js

。_饼干妹妹 提交于 2020-08-06 08:08:26
问题 const fetch = require("node-fetch"); async function getPokemon() { const response = await fetch('https://pokeapi.co/api/v2/pokemon/1'); console.log(response); return response; } getPokemon(); I am not sure this is working. I get back: Response { size: 0, timeout: 0, [Symbol(Body internals)]: { body: Gunzip { _readableState: [ReadableState], readable: true, _events: [Object], _eventsCount: 7, _maxListeners: undefined, _writableState: [WritableState], writable: true, allowHalfOpen: true,

Why File.ReadAllLinesAsync() blocks the UI thread? [closed]

。_饼干妹妹 提交于 2020-08-06 05:37:13
问题 Closed. This question needs debugging details. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 days ago . Improve this question Here is my code. An event handler for WPF button that reads lines of a file: private async void Button_OnClick(object sender, RoutedEventArgs e) { Button.Content = "Loading..."; var lines = await File.ReadAllLinesAsync(@"D:\temp.txt"); //Why blocking UI Thread??? Button.Content =

What is the best way to convert an AsyncRead to a TryStream of bytes?

廉价感情. 提交于 2020-08-02 04:18:26
问题 I have an AsyncRead and want to convert it to a Stream<Item = tokio::io::Result<Bytes>> with tokio 0.2 and futures 0.3. The best I've been able to do is something like: use bytes::Bytes; // 0.4.12 use futures::stream::{Stream, TryStreamExt};; // 0.3.1 use tokio::{fs::File, io::Result}; // 0.2.4 use tokio_util::{BytesCodec, FramedRead}; // 0.2.0 #[tokio::main] async fn main() -> Result<()> { let file = File::open("some_file.txt").await?; let stream = FramedRead::new(file, BytesCodec::new())

How to use async method in DelegateCommand

浪子不回头ぞ 提交于 2020-08-01 09:43:25
问题 I want to link async method to a delegate command in prism framework in Xamarin.Forms and my question is how to do it? Is below solution correct? Is there exist any pitfall? (deadlock, UI slow or freezing, bad practices, ...) { // My view model constructor ... MyCommand = new DelegateCommand(async () => await MyJobAsync()); ... } private async Task MyJobAsync() { ... // Some await calls ... // Some UI element changed such as binded Observable collections } 回答1: You can use async void directly