我有一段非常简单的代码用于测试来自代理服务器的响应,我希望能够启动和停止计时器并获取发生这些事件所花费的时间。但是,我不相信下面的代码是我要找的。p>
var proxyStopWatch = new Timer();
proxyStopWatch.Start();
string[] splitProxy = ProxyList[i].Split('|');
string testResults = HTMLProcessor.HTMLProcessing.HTMLResults("http://www.google.com", splitProxy[0], Convert.ToInt32(splitProxy[1]), true, out testResults);
ProxyListResults.Add(ProxyList+"|"+proxyStopWatch.Interval.ToString());
proxyStopWatch.Stop();
最佳答案
为了得到耗时,Stopwatch类可能会更容易使用。
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
// do stuff
stopWatch.Stop();
long duration = stopWatch.ElapsedMilliseconds;
关于c# - 计时器上耗时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9706803/