From the course: Threading in C#
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Tasks introduction - C# Tutorial
From the course: Threading in C#
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.