private string FormatPerson(UIInformation information) { var formattedPerson = string.Empty; if (int.TryParse(information.Age, out var age)) { var person = new Person( new Name(information.FirstName, information.LastName), age); formattedPerson = $"{person.Name.FirstName} {person.Name.LastName}, {person.Age}"; } return(formattedPerson); }
private void OnCreateViaNonAwaitedTask(object sender, RoutedEventArgs e) { this.SetButtonEnabled(false); var information = new UIInformation { Age = this.ageValue.Text, FirstName = this.firstNameValue.Text, LastName = this.lastNameValue.Text }; var result = Task.Factory.StartNew(() => { return(this.FormatPerson(information)); }); this.SetButtonEnabled(true); }
private async void OnCreateViaTask(object sender, RoutedEventArgs e) { this.SetButtonEnabled(false); var information = new UIInformation { Age = this.ageValue.Text, FirstName = this.firstNameValue.Text, LastName = this.lastNameValue.Text }; var result = await Task.Factory.StartNew(async() => { await Task.Delay(PersonWindow.WaitTime); return(this.FormatPerson(information)); }).Result; this.nameResults.Content = result; this.SetButtonEnabled(true); }