///TimeCheck.cs文件//
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Diagnostics;
namespace ControlCenter
{
public class TimeCheck
{
public System.Diagnostics.Stopwatch stopwatch = new Stopwatch();
public string output = "";
public int index = 0;
public TimeCheck()
{
output = "\n\n";
OutTxt();
}
public void Start()
{
this.stopwatch.Reset();
this.stopwatch.Start();
}
public void Stop(string info)
{
this.stopwatch.Stop();
TimeSpan timespan = stopwatch.Elapsed;
double milliseconds = timespan.TotalMilliseconds;
this.output = info + " 耗时 " + milliseconds.ToString() + " ms.";
this.index = this.index + 1;
OutTxt();
}
public void Reset()
{
this.stopwatch.Reset();
}
public void OutTxt()
{
string path = System.Windows.Forms.Application.ExecutablePath;
FileInfo exeInfo = new FileInfo(path);
path = exeInfo.DirectoryName + "\\";
string fileName = path + "output.txt";
using (StreamWriter stream = File.AppendText(fileName))
{
stream.Write(output + "\r\n");
stream.Close();
}
}
/
}
}
///TimeCheck.cs文件//
调用示例:
TimeCheck tc = new TimeCheck();
tc.Start();
StopCheckMonitorConnenction();
tc.Stop("StopCheckMonitorConnenction()");
tc.Start();
SetSelectDistrict();
tc.Stop("SetSelectDistrict");