我的小程序正在检查脚本网站使用的是什么类型,它使用超过80%的cpu i7处理器.我不知道这是正常的吗?
码:
public static class EnginesMatcher
{
public static readonly Regex Drupal1 =
new Regex(
@"/misc/drupal\.js|Drupal\.settings|href=""http://drupal\.org""|\?q=node/[0-9]+|/\?q=user/register|/\?q=user/password|/user/register\?destination|<li class=""collapsed""><a href=""/node/add"">|/dpl3/files/|/modules/node/",
RegexOptions.Compiled);
public static readonly Regex XE1 =
new Regex(
@"XpressEngine|content=""zeroboardXE|content=""xe_board""|var zbxe_session_name|/xe\.css\?2|/xeicon/favicon\.ico""|#xe-editor-container-1|xpress_xeditor",
RegexOptions.Compiled);
//and 60 more such regex
Run Code Online (Sandbox Code Playgroud)
在另一堂课
public async Task<Result> Match(string url)
{
if (!await Open(url).ConfigureAwait(false)) return ResultKey;
if (EnginesMatcher.Drupal1.IsMatch(html))
{
return new Result()
{
Key = AResultKey.Success,
LogFile = "Drupal.txt",
Message = "Drupal",
Url = url
};
}
if (EnginesMatcher.XE1.IsMatch(html))
{
return new Result()
{
Key = AResultKey.Success,
LogFile …Run Code Online (Sandbox Code Playgroud) 现在,我使用并行方法来检查 200 状态代码的 url,但这种方法很慢。现在我尝试将代码移至等待/异步方法,但它不起作用
private async void button1_Click(object sender, EventArgs e)
{
DateTime start = DateTime.Now;
var timerPostingSpeed = new Timer(state =>
{
TimeSpan elapsed = DateTime.Now - start;
string postingSpeed = string.Format("{0:0}",
finishedUrls * 60 / (int)elapsed.TotalSeconds);
UpdatingLabel(label1, postingSpeed);
}, null, 5000, 10000);
IEnumerable<string> urls = File.ReadLines("urls.txt");
var engine = Python.CreateEngine();
var scriptSource =
engine.CreateScriptSourceFromString(@"
if Open(__URL).Result:
print 1
");
await urls.ForEachAsync(20, async line =>
{
try
{
var adderEngine = new SpeedEngine();
// int zz = await adderEngine.Open(line); …Run Code Online (Sandbox Code Playgroud)