콜백 메서드가 모두 AT가 실행되지 않는 이유는 확실하지 않습니다. 나는 VS 2010WebClient DownloadStringCompleted 콘솔 응용 프로그램에서 결코 실행되지 않음
당신이DownloadDataAsync()
메소드를 호출하면
DownloadDataCompleted
이벤트가 발생한다
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);
}
}
답변을 얻었습니까? –