添加项目文件。
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
|
||||
namespace JinYuan.Helper
|
||||
{
|
||||
/// <summary>
|
||||
/// 操作计时功能
|
||||
/// </summary>
|
||||
public class TimedOperation : IDisposable
|
||||
{
|
||||
private readonly Stopwatch _stopwatch;
|
||||
private readonly string _operationName;
|
||||
private readonly Action<long, string> _onCompleted;
|
||||
private bool _disposed = false;
|
||||
|
||||
public TimedOperation(string operationName, Action<long, string> onCompleted = null)
|
||||
{
|
||||
_stopwatch = Stopwatch.StartNew();
|
||||
_operationName = operationName;
|
||||
_onCompleted = onCompleted;
|
||||
}
|
||||
|
||||
public long ElapsedMilliseconds => _stopwatch.ElapsedMilliseconds;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (!_disposed)
|
||||
{
|
||||
_stopwatch.Stop();
|
||||
_onCompleted?.Invoke(_stopwatch.ElapsedMilliseconds, _operationName);
|
||||
_disposed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user