private async void UpdateTile_Click(object sender, RoutedEventArgs e)
{
// Task hasn't been registered, show message
if (backgroundTrigger == null)
{
MessageDialog infoDialog = new MessageDialog("Can't run task if it hasn't been registered.", "Info");
await infoDialog.ShowAsync();
return;
}
var taskParameters = new ValueSet();
// Send a custom message if we have typed one
if (!string.IsNullOrEmpty(MessageText.Text))
{
taskParameters.Add("Message", MessageText.Text);
}
// Fetch execution results and inform user accordingly
var taskResult = await backgroundTrigger.RequestAsync(taskParameters);
switch (taskResult)
{
default:
case ApplicationTriggerResult.Allowed:
MessageDialog infoDialog = new MessageDialog("Background task successfully executed.", "Info");
await infoDialog.ShowAsync();
break;
case ApplicationTriggerResult.CurrentlyRunning:
case ApplicationTriggerResult.DisabledByPolicy:
case ApplicationTriggerResult.UnknownError:
MessageDialog errorDialog = new MessageDialog("Error running background task: " + taskResult.ToString(), "Error");
await errorDialog.ShowAsync();
break;
}
}
}