AsyncOverSimplified.MoreRealisticAsyncWorker.DoWork C# (CSharp) Method

DoWork() public method

public DoWork ( ) : Task
return Task
        public async Task<int> DoWork()
        {
            int count = 0;


            int resultX = await GetCountAsync("x");
            count = count + resultX;
            Console.WriteLine("X Count is " + count);


            int resultY = await GetCountAsync("y");
            count = count + resultY;
            Console.WriteLine("Y Count is " + count);


            int resultZ = await GetCountAsync("z");
            count = count + resultZ;
            Console.WriteLine("Z Count is " + count);

            return count;
        }

Usage Example

Esempio n. 1
0
 /// <summary>
 /// Runs all 3 variations of the MoreRealistic code to ensure
 /// they all have the same result
 /// </summary>
 /// <returns></returns>
 static async Task MoreRealisticMainAsync()
 {
     var worker = new MoreRealisticAsyncWorker();
     await worker.DoWork();
     await worker.DoWorkExplicitTasks();
     await worker.DoWorkWithoutAwait();
 }
All Usage Examples Of AsyncOverSimplified.MoreRealisticAsyncWorker::DoWork