When the app loads, I would like to parse a local resource file and populate the data structure and then the UI. I would like it to be in a non-UI thread and how do I get it? The file is in Jason format and I'm deserialize it to use the Json.net library. Even when I did this test, the progress bar has not been displayed for this period and I tried to use Toolkit: I do not see the display bar and even the progress bar, so I am thinking that the right What will be the solution.
var resource = System.Windows.Application.GetResourceStream (new URI (string.Format ("testProj; component / {0}", filename), Urikkind.Relative)); Stream reader stream reader = new streamer (resource stream); String jsontext = streamReader.ReadToEnd (); JsonList = JsonConvert.DeserializeObject & lt; List & lt; Comic Title & gt; & Gt; (Jsontext);
The class you need is backgroundworker class class is. You use it like this: - var bw = new backgroundwork () bw.DoWork + = (s, args) => {// It runs on a background thread Var resource = System.Windows.Application.GetResourceStream (new URI (string.Format ("testProj; component / {0}", filename), Uricund.Relative)); Stream reader stream reader = new streamer (resource stream); String jsontext = streamReader.ReadToEnd (); JsonList = JsonConvert.DeserializeObject & lt; List & lt; Comic Title & gt; & Gt; (Jsontext); // other stuff with data}; Bw.RunWorkerCompleted + = (s, args) => {// The work of your UI is here, it will run on the UI thread. // clear progress bar}; // set progress bar bw.RunWorkerAsync (); BTW, are you sure you can not use the DataContractJsonSerializer ? The fact is that you feel the need to do it in a comfortable way, it can suggest that the data is large and the memory is at premium on WP7. The approach of JSON.NET requires that you read the entire JSON stream in the string before you want to delete it, while DataContractJsonSerializer can do the deserializer directly from one stream.
Comments
Post a Comment