AsyncDolls.AsyncPumpScript.CaveatsOfTaskFactoryStartNew C# (CSharp) Method

CaveatsOfTaskFactoryStartNew() private method

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

            Task<Task> pumpTask = Task.Factory.StartNew(async () =>
            {
                while (!token.IsCancellationRequested)
                {
                    #region Output

                    "Pumping...".Output();

                    #endregion

                    await HandleMessage().ConfigureAwait(false);
                }
            }, TaskCreationOptions.LongRunning);

            await pumpTask.Unwrap().ConfigureAwait(false);

            tokenSource.Dispose();
        }