11 Sep

Asynchronous Programming with Async And Await in C# .Net

This page shows how to use async and await keywords for asynchronous programming in C#.
We can avoid performance bottlenecks and enhance the overall responsiveness of our application by using asynchronous programming. However, traditional techniques for writing asynchronous applications can be complicated, making them difficult to write, debug, and maintain. This example uses async and await keywords that coming in .Net Framework 4.5.

Usage :

                Task<int> returnedTaskTResult = TaskOfTResult_MethodAsync();
                int result = await returnedTaskTResult;

Sample :

            // Signature specifies Task<TResult>
            async Task<int> TaskOfTResult_MethodAsync()
            {
                int result;
                // . . .
                // The body of the method should contain one or more await expressions.

                // Return statement specifies an integer result.
                return result;
            }
            
            // Signature specifies Task
            async Task Task_MethodAsync()
            {
                // The body of the method should contain one or more await expressions.

                // The method has no return statement.  
            }

2 thoughts on “Asynchronous Programming with Async And Await in C# .Net

Leave a Reply to lasertest Cancel reply

Your email address will not be published. Required fields are marked *