private Shipment getRates(ref Shipment shipment) { // create an ArrayList of threads, pre-sized to the number of providers. ArrayList threads = new ArrayList(this._providers.Count); // iterate through the providers. foreach(ShippingProviders.AbstractShippingProvider provider in this._providers) { // assign the shipment and ApplyDiscounts value to the provider. provider._shipment = shipment; // setting ApplyDiscounts here is overriding provider-specific settings - commenting it out for now //if(this._applyDiscounts) // provider.ApplyDiscounts = true; // set the ThreadStart method for the thread to the provider's GetRates method. Thread thread = new Thread(new ThreadStart(provider.GetRates)); // assign the thread the name of the provider (for debugging purposes). thread.Name = provider.Name; // start the thread. thread.Start(); // add the thread to our ArrayList. threads.Add(thread); } // loop continuously until all threads have been removed. while(threads.Count > 0) { // loop through the threads (we can't use an iterator since we'll be deleting from the ArrayList). for(int x = (threads.Count - 1); x > -1; x--) { // check the ThreadState to see if it's Stopped. if(((Thread)threads[x]).ThreadState == ThreadState.Stopped) { // it's stopped, so we'll abort the thread and remove it from the ArrayList. ((Thread)threads[x]).Abort(); threads.RemoveAt(x); } } Thread.Sleep(1); } // return our Shipment instance. return shipment; }
/// <summary> /// Retrieves rates for all of the specified providers using the specified address and packages information. /// </summary> /// <param name="originAddress">An instance of <see cref="Address"/> specifying the origin of the shipment.</param> /// <param name="destinationAddress">An instance of <see cref="Address"/> specifying the destination of the shipment.</param> /// <param name="packages">An instance of <see cref="PackageCollection"/> specifying the packages to be rated.</param> /// <returns>A <see cref="Shipment"/> instance containing all returned rates.</returns> public Shipment GetRates(Address originAddress, Address destinationAddress, List<Package> packages) { Shipment shipment = new Shipment(originAddress, destinationAddress, packages); return this.getRates(ref shipment); }
/// <summary> /// Retrieves rates for all of the specified providers using the specified address and packages information. /// </summary> /// <param name="originAddress">An instance of <see cref="Address"/> specifying the origin of the shipment.</param> /// <param name="destinationAddress">An instance of <see cref="Address"/> specifying the destination of the shipment.</param> /// <param name="packages">An instance of <see cref="PackageCollection"/> specifying the packages to be rated.</param> /// <returns>A <see cref="Shipment"/> instance containing all returned rates.</returns> public Shipment GetRates(Address originAddress, Address destinationAddress, List <Package> packages) { Shipment shipment = new Shipment(originAddress, destinationAddress, packages); return(this.getRates(ref shipment)); }