官术网_书友最值得收藏!

  • C# 7 and .NET Core Cookbook
  • Dirk Strauss
  • 241字
  • 2021-07-03 00:11:55

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.

主站蜘蛛池模板: 阳泉市| 蚌埠市| 惠安县| 临猗县| 乌审旗| 中卫市| 阿图什市| 定西市| 连南| 仲巴县| 苍溪县| 泰和县| 洮南市| 青州市| 闸北区| 宣化县| 体育| 罗江县| 商城县| 历史| 宁强县| 桃江县| 稷山县| 文登市| 石林| 汨罗市| 西城区| 新沂市| 象州县| 靖远县| 诸暨市| 临湘市| 景德镇市| 绵阳市| 自贡市| 南汇区| 莱州市| 玉山县| 兰溪市| 乌兰浩特市| 宁津县|