// This method simulates access to a remote database over a slow // network. internal void LoadCustomers() { int i; for (i=0; i < _initialMaxCustomers; i++) { // Simulate slow network access. System.Threading.Thread.Sleep (1000); // Create and add the customer. Customer customer = new Customer(); _customerList.Add (customer); // Shows the user status of obtaining the recordset. Console.Write("."); } Console.WriteLine ("\nLoadCustomers: Loaded {0} customers from the database.", i); }
private void AddNewCustomer() { // Create a new customer record. This will create a new customer // number. Customer c = new Customer(); // Create an instance of the delegate used to read the // data across the slow network. CustomerDataManager.DataAdder adder = new CustomerDataManager.DataAdder(_manager.Add); // Create the delegate that will be used to call // the callback method above. AsyncCallback addResults = new AsyncCallback(AddingDone); // We could have called the delegate directly: reader();. However, // we want to do it asynchronously so well use the BeginInvoke() // method in the delegate instead. This call will return immediately. IAsyncResult iar = adder.BeginInvoke(c, addResults, null); }
internal bool Add(Customer newCustomer) { bool success = true; // First, make sure the customer ID isn't already in the list. foreach (Customer c in _customerList) { if (c.CustomerNumber == newCustomer.CustomerNumber) { Console.WriteLine ("Add: ERROR - Customer with I.D. {0} already exists.", newCustomer.CustomerNumber); success = false; } } if (success) { // Simulate a slow network. System.Threading.Thread.Sleep (7500); // Add the customer to the list. _customerList.Add (newCustomer); // Reset the current index so that we're pointing to // the top of the list of customers. First(); } return success; }
private void AddNewCustomer() { Customer c = new Customer(); if (!_manager.Add(c)) { Console.WriteLine ("Run: ERROR - Could not add customer {0}.", c.CustomerNumber); } else { Console.WriteLine ("Run: Customer {0} was successfully added.", c.CustomerNumber); } }