Skip to content

Commit

Permalink
We don't need use ping to test website speed
Browse files Browse the repository at this point in the history
  • Loading branch information
bao-qian committed May 5, 2016
1 parent e686df6 commit 4088d39
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
31 changes: 10 additions & 21 deletions Plugins/Wox.Plugin.WebSearch/WebSearchPlugin.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -85,28 +82,20 @@ private void UpdateResultsFromSuggestion(List<Result> results, string keyword, s
{
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);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Wox.Plugin/Feature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ public interface IResultUpdated : IFeatures
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;
Expand Down

0 comments on commit 4088d39

Please sign in to comment.