how to make asychronous method calls return a List ?

Hi,

I am using google api to search for youtube videos but unfortunately I can not really resolve that altough i search for the video and get a result in the function i can not return a value from the function thus wont be able to display this on my page.

Ideally what i would want to do is reeturn a List from the function and iterate through each item on the List in razor and display the video but how can i achieve this can you help me?

 public partial class YouTubeConnect : System.Web.UI.Page
    {

        List<string> videos = new List<string>();
        List<string> channels = new List<string>();
        List<string> playlists = new List<string>();
      
        protected void Page_Load(object sender, EventArgs e)
        {
            var youtubeService = new YouTubeService(new BaseClientService.Initializer()
            {
                ApiKey = MazdaContext.Current.Site.GetConfigurationValue("youtubeApiKey"),
                ApplicationName = this.GetType().ToString()
            });
           
            SearchVideo(youtubeService);

        }

        public async void SearchVideo(YouTubeService youtubeService)
        {
            var searchListRequest = youtubeService.Search.List("snippet");
            searchListRequest.Q = "BMW"; //Replace with your search term.
            searchListRequest.MaxResults = 50;

            // Call the search.list method to retrieve results matching the specified query term.
            var searchListResponse = await searchListRequest.ExecuteAsync();

            // Add each result to the appropriate list, and then display the lists of
            // matching videos, channels, and playlists.
            foreach (var searchResult in searchListResponse.Items)
            {
                switch (searchResult.Id.Kind)
                {
                    case "youtube#video":
                        videos.Add(String.Format("{0} ({1})", searchResult.Snippet.Title, searchResult.Id.VideoId));
                        break;

                    case "youtube#channel":
                        channels.Add(String.Format("{0} ({1})", searchResult.Snippet.Title, searchResult.Id.ChannelId));
                        break;

                    case "youtube#playlist":
                        playlists.Add(String.Format("{0} ({1})", searchResult.Snippet.Title, searchResult.Id.PlaylistId));
                        break;

                       
                }
            }
        }
    }

Open in new window

nicedoneAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sarabandeCommented:
you could get a handle to the main window of your app by

pWnd = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;

Open in new window


if that is non-zero post a private message to the window

PostMessage(pWnd, (uint)WM_MY_PRIVATE_YOUTUBE_MSG, 0, 0);

Open in new window


instead of 0 you can past handles to global memory or shared object  to the main window.

the main window could catch the private message in a handler function, then retrieve the list from clipboard, shared or global memory or via a container already provided when the youtube service was called. then display the list in a grid or form.

Sara
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.