From the course: Advanced Threading in C#

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

TaskCompletionSource

TaskCompletionSource - C# Tutorial

From the course: Advanced Threading in C#

Start my 1-month free trial

TaskCompletionSource

- [Instructor] There are times when we want to run the task only when we get some kind of user input. So, for example, if the user fires a certain event, at that particular event, on some kind of name change, we want to be able to add something in the database. Something like 'task completion source class' is very handy to achieve something like that. It will start a background task that will, later, complete that task once some user triggers an event that requires that task to be completed. So we're going to look into the demo and see how that works. First, we'll use 'task completion source'. And we'll create a type, 'product'. We'll clear this type in a second. And we'll initialize it here. You can create it off any particular type you like. I just wanted to use... a class here, rather than just sending back in to make sure this part is a little clear. So we're going to add a new class called 'product'. Again, it could be... public or internal, won't really matter. In this case, use…

Contents