AsyncAwesome.AsyncShowcase.addValuesInRange C# (CSharp) Method

addValuesInRange() public method

public addValuesInRange ( int start, int range ) : Task
start int
range int
return Task
        public async Task addValuesInRange(int start, int range)
        {
            var endIndex = start + range;

            for (var i = start; i < endIndex; i++)
            {
                await this.addValue(i); // each addition is awaited before progressing to the next one
            }
        }

Usage Example

        private async static Task AsyncMain()
        {
            var asyncShow = new AsyncShowcase();

            /*
             * A task can be started and not immediatley awaited.
             */
            var t = Task.Run(() =>
            {
                Thread.Sleep(1000);
                asyncShow.addValuesInRange(0, 10).Wait();
            });

            await asyncShow.addValue(10);                       // add 10 and wait

            Console.WriteLine(await asyncShow.getValueAsync()); // can wait within function call and function will receive argument

            await t;

            if (await asyncShow.getValueAsync() == 55) // I can use await within a conditional
            {
                Console.WriteLine("Success!");
            }
        }
All Usage Examples Of AsyncAwesome.AsyncShowcase::addValuesInRange