您的位置:首页 > 编程语言 > C#

c# 多线程 控制CPU不超过50%

2013-03-28 16:07 162 查看
原文地址: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);
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: