Getting ready

Start off by creating a new WinForms application and performing the following steps:

  1. Add a button, label, timer, and textbox to the Windows form.
  1. We need to add the System.Threading.Tasks.Extensions package from NuGet to implement the  ValueTask<T> struct. This process should be familiar to you if you completed the Tuples recipe. Select the winform project and click on the Install button.
Note that I am using Visual Studio 2017 RC while writing this book. You probably will not need to add System.Threading.Tasks.Extensions from NuGet in the final release.
  1. A confirmation screen will be displayed to allow you to review the changes that are about to be made. Just click on OK. Accept the license agreement. Also make sure that you have added this using statement to your project.
        using System.Threading.Tasks;

We are now ready to write our code. The Windows app will call an async  Task<T> method if the time to live has passed. Once it does that, the method will read a value and cache it. This cached value will be valid for 10 seconds (which is the time to live). If the method is run within the time to live period, then the cached value will be used and returned to the form. If the time to live has passed, the process repeats and the Task<T> method is called. The implementation will become clearer when you review the following code samples.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.114.85