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

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

主站蜘蛛池模板: 农安县| 德阳市| 灵川县| 平昌县| 民权县| 建瓯市| 循化| 孟津县| 鄂托克前旗| 花莲市| 许昌市| 吴川市| 德惠市| 兴宁市| 蓬安县| 西宁市| 巴青县| 特克斯县| 徐水县| 乌拉特前旗| 寿阳县| 九龙城区| 浮山县| 神池县| 武陟县| 胶州市| 呼伦贝尔市| 蛟河市| 竹北市| 娄底市| 梁山县| 建阳市| 怀安县| 额敏县| 株洲市| 绥棱县| 墨脱县| 枝江市| 宁阳县| 古丈县| 景洪市|