From the course: 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.

Tasks introduction

Tasks introduction - C# Tutorial

From the course: Threading in C#

Start my 1-month free trial

Tasks introduction

- [Instructor] Let's look at an example where we can see how we can work with Tasks. In order to work with Task, we will use System.Threading.Tasks. It's very simple as we worked with Threads except now we using Task keyword and we have to add an Action right here. We can just call it SimpleMethod for now, and then resolve the method using Control + dot. And we can do something very simple like Console.WriteLine("Hello World"). It's the same as Threads, so we'll have to specify when to start this Task. Very simply like what we did in case of Threads by using task.Start. Control + F5. As you can see, we got Hello World. However, if you just remember, I mentioned that we could use tasks with a method that would return something. And we can say taskThatReturns equals new task, method that returns a value. Resolve the method. And now we can say, return "Hello" just to make it a little different than hello world. We can say String. Now, you notice that it start giving you an error right…

Contents