ThinkGeo.com    |     Documentation    |     Premium Support

ObjectDisposedException was unhandled


    /// <summary>
    /// Geo Route class to get the class using ThinkGeo Routing Software
    /// </summary>
    public static class GeoRoute
    {
        private static FeatureSource featureSource;
        private static RoutingSource routingSource;

        /// <summary>
        /// Assign Source
        /// </summary>
        /// <param name="freatureSource"></param>
        /// <param name="routingSource"></param>
        public static void AssignSource(string freatureSourcePath, string routingSourcePath)
        {
            featureSource = new ShapeFileFeatureSource(freatureSourcePath);
            routingSource = new RtgRoutingSource(routingSourcePath);
        }

        /// <summary>
        /// Get Driving Distance
        /// </summary>
        /// <param name="startingAddress">Starting Address</param>
        /// <param name="listOfAddress">List of Address</param>
        /// <returns>
        public static List<DrivingDistance> drivingDistance(Coordinate startingAddress, List<GeoCodedAddress> listOfAddress)
        {
            List<DrivingDistance> drivingDistance = new List<DrivingDistance>();

            try
            {
                featureSource.Open();
                routingSource.Open();

                RoutingEngine routingEngine = new RoutingEngine(routingSource, featureSource);

                
                // Loop throught Address
                foreach (GeoCodedAddress coord in listOfAddress)
                {
                    routingEngine.RoutingSource = routingSource;

                    try
                    {
                        if (coord.latitude.Equals(0.00) || coord.latitude.Equals(0.00))
                        {
                            drivingDistance.Add(new DrivingDistance(coord.workAssignmentID, coord.address, 0, false));
                        }
                        else
                        {
                            double distance = routingEngine.GetRoute(new PointShape(startingAddress.Longitude, startingAddress.Latitude),
                                                                     new PointShape(coord.longtitude, coord.latitude)).Distance;

                            drivingDistance.Add(new DrivingDistance(coord.workAssignmentID, coord.address, (distance * 0.621371192), true));
                        }
                    }
                    catch (Exception ex) {
                        System.Diagnostics.Debug.WriteLine(ex.Message);
                        drivingDistance.Add(new DrivingDistance(coord.workAssignmentID, coord.address, 0, false)); }
                }

                featureSource.Close();
                routingSource.Close();

                return drivingDistance;
            }
            catch (Exception) { return null;  }
                
        }
    }

    /// <summary>
    /// Driving Distance class to that holds that driving distance 
    /// </summary>
    [Serializable]
    public class DrivingDistance
    {
        public string workAssignmentID { get; set; }
        public string address {get; set;}
        public double miles {get; set;}
        public bool valid { get; set; }

        public DrivingDistance(string address, double miles, bool valid)
        {
            this.address = address;
            this.miles = miles;
            this.valid = valid;
        }

        // Added by JC on 4/21/2010
        public DrivingDistance(string workAssignmentID, string address, double miles, bool valid)
        {
            this.workAssignmentID = workAssignmentID;
            this.address = address;
            this.miles = miles;
            this.valid = valid;
        }
    }


Hi,


I build a class that gets driving distance between from starting point to mutiple locations. However, we are getting errors such as "ObjectDisposedException was unhandled" and "Can't access a closed file" when mutiple users login on our test server. It even crash our IIS server.  Who would I dispose the objects propertly in my code. Thanks.


 


 



[code] 
  at System.IO.__Error.FileNotOpen()
   at System.IO.FileStream.Flush()
   at ThinkGeo.MapSuite.MapSuiteGeocoder.xb55f028df11b563b.Flush()
   at ThinkGeo.MapSuite.MapSuiteGeocoder.xb55f028df11b563b.Close()
   at ThinkGeo.MapSuite.MapSuiteGeocoder.IndexDbf.Dispose(Boolean disposing)
   at ThinkGeo.MapSuite.MapSuiteGeocoder.IndexDbf.Finalize()
[code]

I am not the Web specialist but I noticed that you are using a static class in a multiple user environment and I think this is going to cause a problem.  I think that this is at least one problem you have. Remove static  from your code and change your code  to have a different object  for your class used for each user. If you still have problem, we will get a developer from the Web edition to answer your concerns. Thank you.