C# Async / Await - Make your app more responsive and faster with asynchronous programming

IAmTimCorey · 1.1M views · 2018 · 38:57

Open on YouTube

Software practice, open source & careersC, C++, Rust, Go & systems languagesWeb developmenttutorial

Why Stack Overflow recommends it

Stack Overflow users link it when answering beginners who are blocking a UI thread or don't yet understand async/await in C#.

Recommended by 6 people across 7 different months, 2019 to 2024.

What it is

A 39-minute C# tutorial by Tim Corey (IAmTimCorey) on using async and await in a WPF-style demo app. It converts a synchronous method to async, runs tasks in parallel, covers best practices, and compares wrapping a method in Task.Run with a true async call.

What people said

Recommends RudolfJan · 2019-06 · Stack Overflow · on “Monitor long running task in c#”

You may watch this video and the second part. It explains quite well how to run backgrond tasks asynchronously: [this video]

Recommends RudolfJan · 2019-06 · Stack Overflow · on “Can I put a cancel button on another thread?”

I recommend to watch this video: [this video] There is a second part, which explains very well how to cancel a background thread. Using threads depends a lot of what you really need. At least this works for me and gives you a nice strting point.

Recommends NigelMassey · 2019-08 · Stack Overflow · on “Basic Understanding of Async Await Programming in C#”

This video [this video] really helped me to understand correct usage of await and what to expect when making/using async methods.

Recommends MindSwipe · 2019-11 · Stack Overflow · on “Task is asynchronous or synchronous without async await?”

The SO post is talking about the `Wait()` method on the Task, if it is called the calling Thread will wait for the execution to be done. If not then the calling thread will move on (but do not call `Wait()` manually, you should always await Tasks). Here are 2 videos that helped me understand async/ await: 1. [this video] 2. [LINK]

Recommends George Kerwood · 2020-05 · Stack Overflow · on “WPF C# How to handle multiple processes?”

There's a lot of question here but what you are looking for is Asynchronous programming. I recommend Tim Corey's YouTube videos as a great place to start: [this video]

Recommends George Kerwood · 2020-05 · Stack Overflow · on “SqlDependency and Console app monitoring changes”

I can't, be Tim Corey can :) [this video] Simply put, your continuous monitoring should be conducted on a thread other than the main application thread. This can be achieved through the use of `Task`, `BackgroundWorker`, or any number of other approaches that I'm not particularity qualified to explain or recommend. This way, you main thread is still free to handle user interactions, such as canceling the monitor, whilst you process is handled continuously else where.

Recommends George Kerwood · 2020-07 · Stack Overflow · on “Multiple small image stitching (orthomosaic, map2d)”

Ignore this if it's not helpful but it may be a better explanation of the parallelization principles: [LINK] And this video for an intro to async programming in C#: [this video]

Recommends TRex · 2021-09 · Stack Overflow · on “Best way to have multiple sequential Process runing without blocking main WPF UI thread?”

Thanks to @TamBui, I found the solution with await/async as he suggested. First I'd like to share the YouTube tutorial that I found extremely pedagogic in this way : [this video] Here is what I modified : My convenient methods : private static Process NetshDNSManaging( string interfaceName, bool isIPv6, bool isPrimary = true, string address = null, EventHandler startHandler = null, EventHandler exittHandler =null ) { if (string.IsNullOrWhiteSpace(interfaceName)) return null; bool noAddress = (string.IsNullOrWhiteSpace(address)); string args = string.Format("interface {0} {1} dnsservers \"{2}\"{3} {4} {5}", isIPv6 ? "ipv6" : "ipv4",//{0} noAddress?"delete":(isPrimary ? "set" : "add"),//{1} interfa

Recommends Azelski · 2022-05 · Stack Overflow · on “How to convert this code to an asynchronous implementation?”

if you only care about the answer here it is: public async Task<List<Person>> SearchPersonAsync(ISearch searcher, string filter) { return await searcher.SearchAsync(filter); } or as comment from @DiplomacyNotWar [LINK] stated just return directly since there is no other logic besides pasing the filter: var result = await searcher.SearchAsync(filter); However, if you're not sure what async/await is about, it wouldn't help you at all and as comments stated even though answer is really basic and simple it won't get you anywhere. It's better to start from learning what's the point of wrapping this logic into async in the first place. General promise is that it's not going to be blocking main thr

Cites Max · 2020-07 · Stack Overflow · on “WPF-App unsuable when using IRC-Client in Twitch [C#]”

Thanks to the comment from aepot [LINK] I looked into async programming. This solution worked for me: I added a function private async Task<string> getChat() { string msg = await Task.Run(() => client.ReadMessage()); return msg; } and changed the dispatcher function to private async void dispatcherTimerChat_tick(object sender, EventArgs e) { string msg = await getChat(); Console.WriteLine(msg); } This tutorial [this video] helped me along the way.