|
|
@@ -3,30 +3,30 @@
|
|
|
namespace YSAI.Unility
|
|
|
{
|
|
|
/// <summary>
|
|
|
- /// 运行耗时
|
|
|
+ /// 时间工具
|
|
|
/// </summary>
|
|
|
- public class RunTimeTool
|
|
|
+ public class TimeTool
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 标识符
|
|
|
/// </summary>
|
|
|
private string ID { get; set; }
|
|
|
- public RunTimeTool(string ID)
|
|
|
+ public TimeTool(string ID)
|
|
|
{
|
|
|
this.ID = ID;
|
|
|
}
|
|
|
|
|
|
private static readonly object Lock = new object(); //锁
|
|
|
- private static List<RunTimeTool> ThisObjList = new List<RunTimeTool>(); //自身对象集合
|
|
|
+ private static List<TimeTool> ThisObjList = new List<TimeTool>(); //自身对象集合
|
|
|
/// <summary>
|
|
|
/// 单例模式
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
- public static RunTimeTool Instance(string ID)
|
|
|
+ public static TimeTool Instance(string ID)
|
|
|
{
|
|
|
lock (ThisObjList)
|
|
|
{
|
|
|
- RunTimeTool? exp = ThisObjList.FirstOrDefault(c => c.ID.Equals(ID));
|
|
|
+ TimeTool? exp = ThisObjList.FirstOrDefault(c => c.ID.Equals(ID));
|
|
|
if (exp == null)
|
|
|
{
|
|
|
lock (Lock)
|
|
|
@@ -37,7 +37,7 @@ namespace YSAI.Unility
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- RunTimeTool exp2 = new RunTimeTool(ID);
|
|
|
+ TimeTool exp2 = new TimeTool(ID);
|
|
|
ThisObjList.Add(exp2);
|
|
|
return exp2;
|
|
|
}
|
|
|
@@ -73,5 +73,18 @@ namespace YSAI.Unility
|
|
|
double milliseconds = timespan.Milliseconds; // 总毫秒数
|
|
|
return (hours, minutes, seconds, milliseconds);
|
|
|
}
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 微秒延时
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="time">延时时间,单位:ms</param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static void DelayUs(double time)
|
|
|
+ {
|
|
|
+ Stopwatch stopTime = new Stopwatch();
|
|
|
+ stopTime.Start();
|
|
|
+ while (stopTime.Elapsed.TotalMilliseconds < time) { }
|
|
|
+ stopTime.Stop();
|
|
|
+ }
|
|
|
}
|
|
|
}
|