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

  • 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.

主站蜘蛛池模板: 洛阳市| 大埔县| 石狮市| 青河县| 英山县| 阿荣旗| 和硕县| 通海县| 宜兴市| 太原市| 古蔺县| 集安市| 九龙城区| 定安县| 武乡县| 沧源| 山东省| 兖州市| 友谊县| 丰顺县| 绿春县| 客服| 明溪县| 石屏县| 沙雅县| 峨边| 门头沟区| 绥棱县| 五家渠市| 恭城| 漾濞| 黔东| 福安市| 苏尼特左旗| 永平县| 兴化市| 黎城县| 施秉县| 湘潭县| 宝山区| 灵丘县|