Skip to content

jeremybytes/using-task-dotnet7

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

I'll Get Back to You: Task, Await, and Asynchronous Methods in C#

There's a lot of confusion about async/await, Task/TPL, and asynchronous and parallel programming in general. So let's start with the basics and look at how we can call asynchronous methods using Task and then see how the "await" operator can makes things easier for us. Along the way, we’ll look at continuations, cancellation, and exception handling.

Code samples (.NET 7) and slides are included in this repository.

Articles and additional resources: http://www.jeremybytes.com/Demos.aspx#TaskAndAwait

Project Layout

To build and run the code, you will need to have .NET 7 installed on your machine. The demo is a Windows desktop application, so it will run on Windows only.

The demo code has a /Starter and /Completed folder. These have the code in its initial state and finished state, respectively.

/People.Service contains a service (used by the desktop application)

/UsingTask.Library contains the library code that calls the service

  • PersonReader.cs contains the asynchronous method used in the desktop application.

/UsingTask.Shared contains the data types 'Person' and 'People'

/UsingTask.UI contains the desktop application

  • MainWindow.xaml.cs contains the code behind that is updated for this demo

Development Environments

Visual Studio 2022
The "UsingTask.sln" contains both of the projects listed above. The service needs to be started along with the desktop application. I generally start the service outside of Visual Studio (see "Running the Service" below) and then have the desktop application set to start in the Visual Studio debugger.

Visual Studio Code
In Visual Studio Code, you will want to start the service separately from the desktop application (see "Running the Service"). You can leave the service running while working with the desktop application.

Running the Service

The .NET service can be started from the command line by navigating to the ".../people-demo/People.Service" directory and typing dotnet run. This provides endpoints at the following locations:

[{"id":1,"givenName":"John","familyName":"Koenig","startDate":"1975-10-17T00:00:00-07:00","rating":6,"formatString":null},  
{"id":2,"givenName":"Dylan","familyName":"Hunt","startDate":"2000-10-02T00:00:00-07:00","rating":8,"formatString":null}, 
{...}]

Resources

Recorded Presentations

Additional Materials

Articles

Video Series

Progress Reporting

Related Topics

Experts

Parallel Programming wtih Task

About

.NET 7 code and slides for "I'll Get Back to You: Task, Await, and Asynchronous Methods in C#"

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages