Esempio n. 1
0
 /// <summary>
 /// 释放资源
 /// </summary>
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         image          = null;
         TranImage      = null;
         TranLaterImage = null;
     }
     if (_tBrush != null)
     {
         _tBrush.Dispose();
         _tBrush = null;
     }
     if (sTimer != null)
     {
         sTimer.Stop();
         sTimer.Dispose();
     }
     if (alpha != null)
     {
         alpha.Dispose();
         alpha = null;
     }
     base.Dispose(disposing);
 }
Esempio n. 2
0
        /// <summary>
        /// 参数为true表示释放所有资源,只能由使用者调用
        /// 参数为false表示释放非托管资源,只能由垃圾回收器自动调用
        /// 如果子类有自己的非托管资源,可以重载这个函数,添加自己的非托管资源的释放
        /// 但是要记住,重载此函数必须保证调用基类的版本,以保证基类的资源正常释放
        /// </summary>
        protected virtual void Dispose(bool disposing)
        {
            // 如果资源未释放
            // 这个判断主要用了防止对象被多次释放
            if (!disposed)
            {
                // 标识此对象已释放
                disposed = true;
                if (disposing)
                {
                    // TODO: 释放托管资源(托管的对象)。
                    _image = null;
                    Tag    = null;
                    Owner  = null;
                }

                // TODO: 释放未托管资源(未托管的对象)并在以下内容中替代终结器。
                // TODO: 将大型字段设置为 null。
                // 未托管资源有: 
                // ApplicationContext, Brush, Component, ComponentDesigner, Container, Context, Cursor,
                // FileStream, Font, Icon, Image, Matrix, Object, OdbcDataReader, OleDBDataReader, Pen,
                // Regex, Socket, StreamWriter, Timer, Tooltip, 文件句柄, GDI资源, 数据库连接等等资源。
                if (_color != null)
                {
                    _color.Dispose();
                    _color = null;
                }
            }
        }