We don't need use ping to test website speed

This commit is contained in:
bao-qian 2016-05-05 20:26:19 +01:00
parent 9191cae144
commit 923f4ed045
2 changed files with 12 additions and 23 deletions

View File

@ -1,13 +1,10 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net.NetworkInformation;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Documents;
using JetBrains.Annotations;
using Wox.Infrastructure.Storage;
using Wox.Plugin.WebSearch.SuggestionSources;
@ -85,28 +82,20 @@ namespace Wox.Plugin.WebSearch
{
if (_settings.EnableWebSearchSuggestion)
{
var waittime = 300;
var fastDomain = Task.Factory.StartNew(() =>
{
var ping = new Ping();
var source = SuggestionSource.GetSuggestionSource(_settings.WebSearchSuggestionSource, Context);
ping.Send(source.Domain);
}, _updateToken).Wait(waittime);
if (fastDomain)
const int waittime = 300;
var task = Task.Run(() =>
{
results.AddRange(ResultsFromSuggestions(keyword, subtitle, webSearch));
}
else
}, _updateToken);
if (!task.Wait(waittime))
{
Task.Factory.StartNew(() =>
task.ContinueWith(_ => ResultsUpdated?.Invoke(this, new ResultUpdatedEventArgs
{
results.AddRange(ResultsFromSuggestions(keyword, subtitle, webSearch));
ResultsUpdated?.Invoke(this, new ResultUpdatedEventHandlerArgs
{
Results = results,
Query = query
});
}, _updateToken);
Results = results,
Query = query
}), _updateToken);
}
}
}

View File

@ -55,9 +55,9 @@ namespace Wox.Plugin
event ResultUpdatedEventHandler ResultsUpdated;
}
public delegate void ResultUpdatedEventHandler(IResultUpdated sender, ResultUpdatedEventHandlerArgs e);
public delegate void ResultUpdatedEventHandler(IResultUpdated sender, ResultUpdatedEventArgs e);
public class ResultUpdatedEventHandlerArgs
public class ResultUpdatedEventArgs : EventArgs
{
public List<Result> Results;
public Query Query;