コード例 #1
0
        public async Task Update(Customer customer, int customerId)
        {
            await Task.Factory.StartNew(() =>
            {
                try
                {
                    BeginProcessing(customerId);
                }
                catch (InvalidOperationException ex)
                {
                    GenerateMessage(ex.Message);
                    return;
                }
                GenerateMessage("Connecting to server . . .");
                Thread.Sleep(500);
                GenerateMessage("Updating customer . . .");
                Thread.Sleep(4000);
                var customerToUpdate = Customers.FirstOrDefault(c => c.Id == customerId);
                if (customerToUpdate == null)
                {
                    GenerateMessage($"Customer ID = {customerId} not found");
                }
                else
                {
                    customerToUpdate.FirstName = customer.FirstName;
                    customerToUpdate.LastName  = customer.LastName;
                    customerToUpdate.Age       = customer.Age;

                    DatasourceChanged?.Invoke(this, Customers);

                    GenerateMessage($"Customer ID = {customerId} has been updated");
                }
                EndProcessing(customerId);
            });
        }
コード例 #2
0
 private void _customers_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
 {
     DatasourceChanged?.Invoke(this, Customers);
 }
コード例 #3
0
 protected virtual void OnDatasourceChanged()
 {
     DatasourceChanged?.Invoke(this, EventArgs.Empty);
 }