zoukankan      html  css  js  c++  java
  • async与await初步应用






    using
    System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form2 : Form { class Servo { bool bIsInPosi = false; public void StartMove() { this.bIsInPosi = false; } public bool IsInPosi() { return this.bIsInPosi; } public void Debug_InPosi() { this.bIsInPosi = true; } } Servo testServo = new Servo(); public Form2() { InitializeComponent(); } private void Form2_Load(object sender, EventArgs e) { } async private void btnStartMove_Click(object sender, EventArgs e) { Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " " + "运动开始"); testServo.StartMove(); bool bResult = await IsFinish(); Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " " + "运动结束了,结果=" + bResult.ToString()); } async Task<bool> IsFinish() { int timeOutSeconds = 10; DateTime dtStart = DateTime.Now; bool loop = true; while (loop) { await Task.Delay(100); if (testServo.IsInPosi()) { return true; } TimeSpan ts = DateTime.Now - dtStart; if (ts.TotalSeconds >= timeOutSeconds) { Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss.fff") + " " + "运动超时了"); return false; } } return false; } private void btnInPosi_Click(object sender, EventArgs e) { testServo.Debug_InPosi(); } } }
  • 相关阅读:
    格子地图生成导航网格
    Geometry Shader 实现 Wireframe 绘制边线的Shader
    体素爆炸
    弹孔,血迹 等受击表现
    Behaviac 腾讯开源行为树 简介(给策划)
    unable to unroll loop 报错
    Unity编辑器扩展
    追踪弹路径
    代码管理资源属性
    主机排行网重大更新,移动端自适应
  • 原文地址:https://www.cnblogs.com/LongHuaiYu/p/10064093.html
Copyright © 2011-2022 走看看