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

View File

@@ -55,9 +55,9 @@ namespace Wox.Plugin
event ResultUpdatedEventHandler ResultsUpdated; 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 List<Result> Results;
public Query Query; public Query Query;