我有一个从网上下载csv文件的功能。我需要扩展它,以便对2个网站依次进行2个呼叫。但是我不知道该怎么办呢?Rx Observable - 链接
继承人的功能:
// Define other methods and classes here
private void GetCSVData(string url1, string url2)
{
WebClient webClient = null;
try
{
webClient = new WebClient();
var task = Observable.FromEventPattern
<OpenReadCompletedEventHandler, OpenReadCompletedEventArgs>
(
ev => webClient.OpenReadCompleted += ev,
ev => webClient.OpenReadCompleted -= ev
);
// needs to be redone
task.Subscribe(t => ParseCSV1(t.EventArgs.Result));
// call ParseCSV1()
// then call ParseCSV2()
// needs redone, 2 calls to 2 website
webClient.OpenReadAsync(new Uri(url1));
}
catch (WebException wex)
{
System.Diagnostics.Debug.WriteLine(wex.ToString());
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
}
}
private void ParseCSV1(Stream stream)
{
// Parse steps...
}
private void ParseCSV2(Stream stream)
{
// Parse steps...
}
您的代码似乎不完整。你有'url1'&'url2'进来,但你用'url'调用'OpenReadAsync'。你的代码目的不清楚。你能改善这个问题吗? – Enigmativity 2012-03-23 00:12:03
将2个网址映射到2个可观察对象,将这2个可观察对象连接以获得单个可观察对象并订阅它 – Ankur 2012-03-25 12:38:58