我发现了一个巨大的页面上进行高效的异步调用以最小的努力在这里Web服务:异步回调函数完成后是否会引发事件?
我感到困惑的是,我在哪里把我想执行的代码后的反应是从服务器收到?发生这种情况时系统是否发生事件?在调用asyncdownload之后简单地放置代码并不会提供此功能。
我应该更清楚了;我的项目中有这样的代码:
private void SearchBarcode(object sender, EventArgs e)
{
WebClient wc = new WebClient();
var o = Observable.FromEvent<DownloadStringCompletedEventArgs>(wc, "DownloadStringCompleted")
// Let's make sure that we’re on the thread pool
.ObserveOn(Scheduler.ThreadPool)
// When the event fires, just select the string and make
// an IObservable<string> instead
.Select(newString => ProcessString(newString.EventArgs.Result))
// Now go back to the UI Thread
.ObserveOn(Scheduler.Dispatcher)
// Subscribe to the observable, and set the label text
.Subscribe(s => parserInput = s);
wc.DownloadStringAsync(new Uri("http://api.search.live.net/xml.aspx?Appid=appidhere&query=barcodenumber&sources=web"));
}
我看不到我可以放置DownloadCompleted事件调用的位置。 SearchBarcode是一个图像的onclick处理程序; SearchBarcode执行后控件的位置在哪里?我想操纵parserInput的值并调用另一个传递这些值的xaml页面。我尝试添加一个void DownloadCompleted(object sender,DownloadStringCompletedEventArgs e),但它显然不会被调用。我在这里错过了什么? :(
您是否请详细解释一下您想要的内容?您在“DownloadCompleted”事件处理程序中放置的代码将在下载完成后运行。所以你想要什么比它更多?或者有什么问题呢? – 2010-12-16 09:37:17
仅供参考,会引发事件。错误被抛出。 – 2010-12-16 11:10:13
伙计们,我编辑了我的问题,以更具体。感谢您的期待:D – Freakishly 2010-12-17 19:03:47