Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }