BlogEngine makes Hulk Angry!

B3y steven 9/27/2008 9:25:00 AM

Gotta say getting syntax highlighting working properly in BlogEngine is a real PITA.

Working on this theory but it seems currently Code Highlighting is broken. :(

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

Using, IDisposable and Such

B3y steven 9/16/2008 7:38:00 AM

I was messing with a PDF generating class (PDFSharp, an excellent free .NET PDF Toolkit for creating PDF's) and had to create a class that will load up some images (logos, watermarks, etc.) and then use those for the PDF. The problem is that these type objects are GDI+ type objects and are unmanaged objects. This became a problem because the logos I created during the PDF generation would remain in an opended state by the PDF generation class. This prevented me from deleting the logo file and just really pissed me off.

So IDisposable to the rescue. This allows me to manually manage the disposal of the unmanaged objects and then I could implement the PDF generation class in a using and viola! I was able to delete the image file with no issues.

Here and Here are a couple of great websites with notes and hints about implementing the IDisposable interface in C#.  

The only part that got me is the Finalizer and realizing that the Finalizer is called when the object is destructed by the GC. This is not safe to assume this is at the same time that the object is being disposed (end of a Using statement). So that is why some of the examples you find will have a Dispose(false) to a Dispose method. This prevents the managed objects from being collected in the destructor as the order is unpredictable. If that makes sense to you, great!

Here is a very simple class implementing the IDisposable interface; 

  

Enjoy!

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

Powered By BlogEngine Enhanced with Snapshots

About the author

Steven Hildreth Steven Hildreth
Proof that anyone can setup a blog.

E-mail me LinkedIn Profile

Send mail Sign in

Recent posts