I have a small uwp app running with mvvm pattern that needs to load a big JSON file at some point during execution. I want to print a message box with an indeterminate progress ring control until the deserialization is complete.
I thought of awaiting for the result of JsonConvert.DeserializeObject
asynchronously and printing the message box in the meantime.
Something like this :
MyClass Deserialize(string text, JsonSerializerSettings settings)
{
MyClass result = JsonConvert.DeserializeObject<MyClass>(text, settings);
}
private async void LoadingScreenAsync()
{
var dialog = new MessageDialogWithFancySpinningRing(); // I actually don't know how to do it though ;)
await dialog.ShowAsync();
}
var deserializeTask = Deserialize(MyText, MySettings);
Var LoadingScreenTask = LoadingScreenAsync();
MyClass Result = await deserializeTask;
await dialog.ShowAsync();
// ... continue with result
Though I haven't tried it yet because, from what I've read, I figured it wouldn't work since Deserialize
and JsonConvert.DeserializeObject
aren't async methods. It seams I would need to run the deserialization on another thread for that which looks like a lot of trouble for such a simple thing.
Any ideas ?