PowerArgs.ContextAssistSearch.DoSearch C# (CSharp) Method

DoSearch() private method

private DoSearch ( string searchString ) : void
searchString string
return void
        private void DoSearch(string searchString)
        {
            // as soon as this next line runs, any in flight searches become invalid
            var myRequestId = expireableAsyncRequestManager.BeginRequest();
            var backgroundSearchTask = new Task(() =>
            {
                try
                {
                    List<ContextAssistSearchResult> results;

                    try
                    {
                        if (SupportsAsync)
                        {
                            var userAsyncTask = GetResultsAsync(searchString);
                            userAsyncTask.Wait();
                            results = userAsyncTask.Result;
                        }
                        else
                        {
                            results = GetResults(searchString);
                        }
                    }
                    catch (Exception ex)
                    {
                        PowerLogger.LogLine("Exception fetching results on search provider: " + GetType().FullName + "\n\n" + ex);
                        return;
                    }

                    lock (searchReader.SyncLock)
                    {
                        expireableAsyncRequestManager.EndRequest(() =>
                        {
                            // this block of code only runs if these results are from the most recent request and
                            // the original called of the search assist still cares about results.

                            selectedIndex = 0;
                            latestResults.Clear();
                            latestResults.AddRange(results);
                            latestResultsSearchString = searchString;
                            RedrawSearchResults();
                        }, myRequestId);
                    }
                }catch(Exception ex)
                {
                    PowerLogger.LogLine("Background exception is search provider: " + GetType().FullName + "\n\n" + ex);
                }

            });
            backgroundSearchTask.Start();
        }