System.IO.MemoryStream.Dispose C# (CSharp) Method

Dispose() protected method

protected Dispose ( bool disposing ) : void
disposing bool
return void
        protected override void Dispose(bool disposing)
        {
            try
            {
                if (disposing)
                {
                    _isOpen = false;
                    _writable = false;
                    _expandable = false;
                    // Don't set buffer to null - allow TryGetBuffer & ToArray to work.
                }
            }
            finally
            {
                // Call base.Close() to cleanup async IO resources
                base.Dispose(disposing);
            }
        }

Usage Example

Beispiel #1
1
        public virtual IDisposable Draw(DrawingContext drawingContext, Rect targetItemRect, int level)
        {
            //Default is to draw the image bits into the context:

            //Do not dispose of the memory stream here, because System.Media.Windows uses
            // retained mode rendering where the commands get batched to execute later.
            MemoryStream imageStream = new MemoryStream(this.ImageData);
            try
            {
                TransformedBitmap shrunkImage = ResizePng(imageStream, targetItemRect.Size);

                //DrawingContext.DrawImage will scale an image to fill the size, so modify
                // our target rect to be exactly the correct image position on the tile.
                Rect targetImageRect = new Rect(targetItemRect.X, targetItemRect.Y,
                    shrunkImage.PixelWidth, shrunkImage.PixelHeight);
                drawingContext.DrawImage(shrunkImage, targetImageRect);

                return imageStream; //Return our stream so it can be disposed later.
            }
            catch
            {
                if (null != imageStream)
                {
                    imageStream.Dispose();
                }
                throw;
            }
        }
All Usage Examples Of System.IO.MemoryStream::Dispose