Falcon.SugarApi/Falcon.SugarApi.Test/ShakingTests.cs

43 lines
1.3 KiB
C#
Raw Normal View History

2024-07-01 17:18:51 +08:00
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Falcon.SugarApi.Test
{
/// <summary>
/// 任务防抖测试
/// </summary>
[TestClass()]
public class ShakingTests
{
/// <summary>
/// 任务防抖测试
/// </summary>
[TestMethod()]
public void RunTest() {
var showMsg = () => Console.WriteLine($"{DateTime.Now.ToString("HH:mm:ss")} show message!");
var reMsg = () => $"{DateTime.Now.ToString("HH:mm:ss")} show message!";
var task = new Task<string>(reMsg);
int span = 5;
var shaking = new Shaking(span);
//showMsg();
//await Task.Delay(5 * 1000);
//shaking.Run(showMsg);
Console.WriteLine($"以下方法调用3次应该有两个输出相隔{span}秒");
Console.WriteLine(reMsg());
shaking.Run(task);
task = new Task<string>(reMsg);
shaking.Run(task);
Console.WriteLine($"{DateTime.Now.ToString("HH:mm:ss")} {span}秒后记录第二个输出");
Console.WriteLine(task.Result);
Console.WriteLine("任务完成!");
}
}
}