private void QueryExecutionCompleted(Task <LoadPageResult> task)
        {
            // If a task throws, the exception must be handled or the Exception
            // property must be accessed or the exception will tear down the process when finalized
            Exception exception = task.Exception;

            if (task.IsFaulted)
            {
                try
                {
                    ExceptionHelper.WriteToActivityLog(exception);
                }
                catch
                {
                    // don't let this crash VS
                }
            }

            var cancellationSource = (CancellationTokenSource)task.AsyncState;

            if (cancellationSource != _currentCancellationSource)
            {
                return;
            }

            _loadingInProgress = false;

            // Only process the result if this node is still selected.
            if (IsSelected)
            {
                if (!task.IsCanceled && !cancellationSource.IsCancellationRequested)
                {
                    if (task.IsFaulted)
                    {
                        // show error message in the Message pane
                        ShowMessagePane(ExceptionUtility.Unwrap(exception).Message);
                    }
                    else
                    {
                        // completed successfully - display the results
                        LoadPageResult result = task.Result;

                        UpdateNewPackages(result.Packages.ToList());

                        int totalPages = (result.TotalCount + PageSize - 1) / PageSize;
                        TotalPages  = Math.Max(1, totalPages);
                        CurrentPage = Math.Max(1, result.PageNumber);
                    }
                }

                HideProgressPane();
            }

            Provider.OnPackageLoadCompleted(this);

            // for unit tests
            PackageLoadCompleted(this, EventArgs.Empty);
            NuGetEventTrigger.Instance.TriggerEvent(NuGetEvent.PackageLoadEnd);
        }
        private void QueryExecutionCompleted(Task <LoadPageResult> task)
        {
            // If a task throws, the exception must be handled or the Exception
            // property must be accessed or the exception will tear down the process when finalized
            Exception exception = task.Exception;

            var cancellationSource = (CancellationTokenSource)task.AsyncState;

            if (cancellationSource != _currentCancellationSource)
            {
                return;
            }

            _loadingInProgress = false;

            // Only process the result if this node is still selected.
            if (IsSelected)
            {
                if (task.IsCanceled)
                {
                    HideProgressPane();
                }
                else if (task.IsFaulted)
                {
                    // show error message in the Message pane
                    ShowMessagePane((exception.InnerException ?? exception).Message);
                }
                else
                {
                    LoadPageResult result = task.Result;

                    IEnumerable <IPackage> packages = result.Packages;

                    _extensions.Clear();
                    foreach (IPackage package in packages)
                    {
                        _extensions.Add(Provider.CreateExtension(package));
                    }

                    if (_extensions.Count > 0)
                    {
                        _extensions[0].IsSelected = true;
                    }

                    int totalPages = (result.TotalCount + PageSize - 1) / PageSize;
                    int pageNumber = result.PageNumber;

                    TotalPages  = Math.Max(1, totalPages);
                    CurrentPage = Math.Max(1, pageNumber);

                    HideProgressPane();
                }
            }

            if (QueryExecutionCallback != null)
            {
                QueryExecutionCallback();
            }
        }