开发者

Silverlight Asnyc method not executed

开发者 https://www.devze.com 2023-03-12 17:56 出处:网络
I\'m working on a Silverlight site, which requires m开发者_如何学Ce to read from an XML file. This file is located server-side. The user cannot select one of their own files.

I'm working on a Silverlight site, which requires m开发者_如何学Ce to read from an XML file. This file is located server-side. The user cannot select one of their own files.

Silverlight cannot read files in its own folders. Only via OpenFileDialog can Silverlight read a file, but this file is uploaded by the user and considered to be a stream. As I said before, the file I need to read is not uploaded, but resides in the same map as the XAP file. Here's a screenshot of my VS2010 solution explorer:

Silverlight Asnyc method not executed

So, as you can see, the file is included. Do note: this is not intended to become a finished product, it's just something I'm working on to get to know Silverlight better.

I got the code I am using from this blog: http://blogs.silverlight.net/blogs/msnow/archive/2009/02/10/silverlight-tip-of-the-day-93-reading-xml-with-silverlight.aspx

I've pasted the entire class in a pastebin page, as it is a little much to paste here(but not too much to give it a read :P ): http://pastebin.com/eEMGGxsB

The method tied to the DownloadStringCompleted EventHandler is never executed. Nor will the Debugger step in to it.

Can anyone tell me what it is that's going on here?


The code that is making the call to DownloadStringAsync looks reasonable. Whenever you have a problem like this the first port of call is Fiddler. Use that to determine exactly what conversation the client is actually having with the server.

One immediate fail I see in the code for the completed event is you are accessing the e.Result before testing whether e.Error has a value. Accessing the Result when Error contains an exception will cause that exception to be thrown. Hence in your code if you haven't put your break point right at the top of the event handler it will never be reached if there is some problem with the download.

Another issue with the code is that your displaySnippet method is run before the completed event and therefore will be trying to access an as yet unpopulated codeList. Don't forget this is asynchronous code, you will want to execute displaySnippet at the end of the completed routine.

0

精彩评论

暂无评论...
验证码 换一张
取 消