How to render reports asynchronously by using the async and await keywords
Environment
Product | Progress® Telerik® Reporting |
Framework | .NET Framework 4.5 and higher |
Description
With the new .NET Framework (4.5), a new way to handle parallel programming has been added - with the help of the Task<> class and the keywords async and await, parallel programming has become much easier. This raises the question, how can these features be used with Telerik Reporting?
Solution
First, we will have to start with the ReportProcessor class and its RenderReport method, which provides all the needed functionality for programmatic generation of reports. Since RenderReport returns RenderingResult, in order to use it asynchronously, you will have to create a method that returns this result. However, since we want to achieve the task in an async manner, we will take advantage of the Task class:
Besides declaring the return value to be Task<RenderingResult> we have marked the method as async. Also, we are invoking the RenderReport method using the await keyword. For the second part, we will use our method in an async manner:
Finally, we will invoke this method in a console application and check the results:
Additional Resources
Download a sample console application.