Tasktask = Task .Factory.StartNew(() => { // Do some complex operation here... return 42; }); // Wait for the task to complete and get the result int result = task.Result;
Tasktask1 = Task .Factory.StartNew(() => { // Do some complex operation here... return 42; }); Task task2 = task1.ContinueWith((t) => { int result = t.Result; return $"The answer is {result}"; }); // Wait for the continuation task to complete and get the result string finalResult = task2.Result;
TaskIn this example, we create two tasks, `task1` and `task2`, that run concurrently. We use `Task.WaitAll()` method to wait for both tasks to complete before proceeding. We use the `Result` property to get the results of both tasks after they complete. The package library used in these examples is `System.Threading.Tasks`, which is part of the .NET Framework and .NET Core runtime.task1 = Task .Factory.StartNew(() => { // Do some complex operation here... return 42; }); Task task2 = Task .Factory.StartNew(() => { // Do some other complex operation here... return 100; }); Task.WaitAll(task1, task2); // Get the results of both tasks int result1 = task1.Result; int result2 = task2.Result;