WebClient DownloadStringCompleted Never Fired in Console Application

Posted by azamsharp on Stack Overflow See other posts from Stack Overflow or by azamsharp
Published on 2010-05-08T01:40:01Z Indexed on 2010/05/08 1:48 UTC
Read the original article Hit count: 445

Filed under:

I am not sure why the callback methods are not fired AT ALL. I am using VS 2010.

 static void Main(string[] args)
        {
            try
            {
                var url = "some link to RSS FEED"; 
                var client = new WebClient();
                client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
                client.DownloadDataCompleted += new DownloadDataCompletedEventHandler(client_DownloadDataCompleted);

                client.DownloadStringAsync(new Uri(url));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message); 
            }
        }
        // THIS IS NEVER FIRED 
        static void client_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
        {
            Console.WriteLine("something"); 
        }

        // THIS IS NEVER FIRED 
        static void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            Console.WriteLine("do something");

            var rss = XElement.Parse(e.Result);

            var pictures = from item in rss.Descendants("channel")
                           select new Picture
                           {
                               Name = item.Element("title").Value
                           };

            foreach (var picture in pictures)
            {
                Console.WriteLine(picture.Name);
                Console.WriteLine(picture.Url);
            }

        }

© Stack Overflow or respective owner

Related posts about ASP.NET