AsyncAwesome.AsyncShowcase.getValueAsync C# (CSharp) Method

getValueAsync() public method

public getValueAsync ( ) : Task
return Task
        public async Task<int> getValueAsync()
        {
            if(Value % 2 == 0)
                return await Task.Run(() => Value); // asynchronous getter
            else return Value;
        }

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::getValueAsync