Skip to content

Instantly share code, notes, and snippets.

@damirarh
Created May 5, 2013 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save damirarh/5520255 to your computer and use it in GitHub Desktop.
Save damirarh/5520255 to your computer and use it in GitHub Desktop.
private readonly Task _initializingTask;
public ViewModel()
{
_initializingTask = Init();
}
private async Task Init()
{
var file = await Package.Current.InstalledLocation.GetFileAsync(@"Assets\Text.txt");
Text = await FileIO.ReadTextAsync(file);
}
private async void OnSomeCommand()
{
// check if initialization is complete
if (_initializingTask.IsCompleted)
{
// do some action
}
// or even await the initialization to complete if it hasn't already
await _initializingTask;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment