原文地址:http://www.docin.com/p-1138045.html
编程之美 让CPU占用率曲线听你指挥
例子:
public void PublishDetailItem(object obj)
{ Usp_Gif_GetGifInfosResult gif = obj as Usp_Gif_GetGifInfosResult; string content = string.Empty; string imgDetailPath = string.Empty; imgDetailPath = string.Format(MyConfig.GifLibResDirPath_Publish + "{0}\\{1}-{2}.html", gif.TagSpell, gif.TagID.ToString(), gif.GifID.ToString()); content = RequestHelper.DownLoadHtml(string.Format(MyConfig.GetQQtuHref + "detail.aspx?tagid={0}&gifid={1}", gif.TagID.ToString(), gif.GifID.ToString()), null, Encoding.UTF8); FileHandler.WriteOnce(imgDetailPath, content, Encoding.UTF8); threadFlag++; PerformanceCounter p = new PerformanceCounter("Processor", "% Processor Time", "_Total"); while (true) { if (p.NextValue() > 50.0) { Thread.Sleep(1000); } } }