Ejemplo n.º 1
0
        /// <summary>
        /// Performs the actual disposing of the Session and the underlying data structure.
        /// </summary>
        /// <param name="disposing"></param>
        protected virtual void Dispose(bool disposing)
        {
            Log.Write("Session.Dispose({0})", disposing);

            if (disposed)
            {
                return;
            }

            if (disposing)
            {
                lock (deviceConnections)
                {
                    while (deviceConnections.Values.Count > 0)
                    {
                        var deviceConnection = deviceConnections.Values.First().Target as DeviceConnection;
                        if (deviceConnection != null)
                        {
                            deviceConnection.Dispose();
                        }
                    }
                }

                if (handle.IsInvalid == false)
                {
                    //try
                    //{
                    handle.Dispose();
                    //}
                    //catch (Exception ex)
                    //{
                    //    Log.Write(ex.ToString());
                    //}
                }

                owner.Unregister(this);
            }

            disposed = true;
        }