Esempio n. 1
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            GraphicsResourceImplementation impl = this.Implementation;

            if (impl != null)
            {
                if (!impl.IsDisposed && disposing)
                {
                    impl.Dispose();
                }
            }
        }
Esempio n. 2
0
 public void AddTrackedObject(IntPtr pointer, GraphicsResourceImplementation impl)
 {
     lock (_syncObject) {
         ResourceData data;
         if (_resources.TryGetValue(pointer, out data))
         {
             //If get same pointer, consider the old resource to have been disposed of
             data.Pointer        = pointer;
             data.ManagedObject  = new WeakReference(impl);
             _resources[pointer] = data;
         }
         else
         {
             data.Pointer       = pointer;
             data.ManagedObject = new WeakReference(impl);
             _resources.Add(pointer, data);
         }
     }
 }
Esempio n. 3
0
 public void ReleaseAllResources()
 {
     lock (_syncObject) {
         IntPtr[] keys = new IntPtr[_resources.Keys.Count];
         _resources.Keys.CopyTo(keys, 0);
         foreach (IntPtr key in keys)
         {
             ResourceData data;
             if (_resources.TryGetValue(key, out data))
             {
                 if (data.ManagedObject.IsAlive)
                 {
                     GraphicsResourceImplementation target = data.ManagedObject.Target as GraphicsResourceImplementation;
                     if (target != null && !target.IsDisposed)
                     {
                         target.Dispose();
                     }
                 }
             }
         }
         _resources.Clear();
     }
 }
Esempio n. 4
0
 //Sets a resource tracking ID.
 private void SetGraphicsID(GraphicsResourceImplementation impl)
 {
     impl.ResourceID = _idCount;
     _idCount++;
 }