AsyncDolls.AsyncTplScript.CancelllingTheOperationInsideTheTask C# (CSharp) Method

CancelllingTheOperationInsideTheTask() private method

private CancelllingTheOperationInsideTheTask ( ) : Task
return Task
        public async Task CancelllingTheOperationInsideTheTask()
        {
            var tokenSource = new CancellationTokenSource();
            tokenSource.CancelAfter(TimeSpan.FromSeconds(5));
            var token = tokenSource.Token;

            var cancelledTask = Task.Run(async () => { await Task.Delay(TimeSpan.FromMinutes(1), token); }, token); // Passing in the token only means the task is transitioning into cancelled state
           
            #region Output

            cancelledTask.Status.ToString().Output();

            #endregion

            try
            {
                await cancelledTask;
            }
            catch (OperationCanceledException)
            {
                #region Output

                "Throws when awaited".Output();
                cancelledTask.Status.ToString().Output();

                #endregion
            }
        }