本文整理汇总了C#中ITokenSource.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# ITokenSource.Dispose方法的具体用法?C# ITokenSource.Dispose怎么用?C# ITokenSource.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITokenSource
的用法示例。
在下文中一共展示了ITokenSource.Dispose方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Query
private List<Result> Query(Query query, ITokenSource cancelToken)
{
if (query.KeywordComplete && query.HasArguments) {
// check the cache for a matching result
var cacheKey = query.Arguments;
var cachedSuggestions = MemoryCache.Default.Get(cacheKey) as List<string>;
// if cached result is found, return it.
if (cachedSuggestions != null) {
// convert the list of suggestion strings to a List<Result>
if (cachedSuggestions.Any()) {
var results = cachedSuggestions.Select(suggestion => new Result
{
Title = suggestion,
Icon = _icon,
SubTitle = "Search google for " + suggestion,
Launch = query1 =>
{
Process.Start($"http://google.co.uk/search?q={suggestion}");
AppCommands.HideWindow();
}
}).ToList();
return results;
}
// no suggestions were received from the server
return new List<Result>
{
new Result
{
Title = "No search suggestions found.",
Icon = _icon
}
};
}
// Cache miss, begin the background query to fill the cache
// create a local cancel token for passing to httpclient..
var cancellable = new CancellationToken();
cancellable.Register(() =>
{
cancelToken.Cancel();
cancelToken.Dispose();
});
var x = GetSuggestionsAsync(query.Arguments, cancellable);
return new List<Result>
{
new Result
{
Title = "Retrieving search suggestions...",
Icon = _icon
}
};
}
// otherwise the query has not been provided yet, running the action will autocomplete the query
return new List<Result>
{
new Result
{
Title = "Search Google",
SubTitle = "Search Google with Suggestions",
Icon = _icon,
Launch = query1 => AppCommands.RewriteQuery(Keyword + ' ')
}
};
}