// Copyright © 2017 The CefSharp Authors. All rights reserved. // // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. using System; using System.Collections.Generic; using System.Threading.Tasks; using CefSharp.Internals; namespace CefSharp { /// /// Provides a visitor implementation of /// public class TaskWebPluginInfoVisitor : IWebPluginInfoVisitor { private TaskCompletionSource> taskCompletionSource; private List list; /// /// Default constructor /// public TaskWebPluginInfoVisitor() { taskCompletionSource = new TaskCompletionSource>(); list = new List(); } bool IWebPluginInfoVisitor.Visit(WebPluginInfo plugin, int count, int total) { list.Add(plugin); //Return true to keep visiting plugins return true; } /// /// Task that can be awaited for the result to be retrieved async /// public Task> Task { get { return taskCompletionSource.Task; } } void IDisposable.Dispose() { //Set the result on the ThreadPool so the Task continuation is not run on the CEF UI Thread taskCompletionSource.TrySetResultAsync(list); list = null; taskCompletionSource = null; } } }