Geeks With Blogs
Blog Moved to http://podwysocki.codebetter.com/ Blog Moved to http://podwysocki.codebetter.com/
Lately, I've been working with a lot of Managed C++ and creating a managed wrapper for the Background Intelligent Information Service (BITS).  As time goes along, I will get deeper into the code, but for now I'll just cover the little topics as they come up.
As always I run FX Cop, which is available here http://www.gotdotnet.com/team/fxcop/ to validate my coding.  I ran across the rule "ImplementIDisposableCorrectly".  Unfortunately, when I click on the link to check for resolution for my problem, I ran across a less than friendly site to help me:
 
No documentation present for ImplementIDisposableCorrectly
No documentation is present yet for ImplementIDisposableCorrectly. Please check this page for updates soon.
 
So, I decided to do my own little bit of research and discovered that sure enough I needed to do a bit of tweaking.  Here is the header file declaration to satisfy the rule:
 
public:
     // Class finalizer
     ~BackgroundCopyFile();
 
     // Public dispose method
     __sealed void Dispose();
protected:
     // Overrideable dispose method
     virtual void Dispose(bool disposing);
 
And the implementations of the header file is below:
 
// BackgroundCopyFile finalizer
Podwysocki::Services::BackgroundTransferServices::BackgroundCopyFile::~BackgroundCopyFile()
{
      // Call dispose
      Dispose(false);
} // finalizer- BackgroundCopyFile
 
// Dispose method
void Podwysocki::Services::BackgroundTransferServices::BackgroundCopyFile::Dispose()
{
      // Call dispose
      Dispose(true);
 
     // Suppress finalize
     GC::SuppressFinalize(this);
} // method - BackgroundCopyFile::Dispose
 
// Overrideable dispose method
void Podwysocki::Services::BackgroundTransferServices::BackgroundCopyFile::Dispose(bool disposing)
{
      // Check if already disposed
      if(!isDisposed)
      {
          // Release unmanaged pointer
           pCopyFile->Release();
      } // if - !isDisposed
 
      isDisposed = true;
} // method - BackgroundCopyFile::Dispose(bool)
 
In further entries, I will dig deeper into the unmanaged and managed code sitting side by side with regards to BITS.
 
Posted on Thursday, May 4, 2006 9:54 AM .NET | Back to top


Comments on this post: Managed C++ and IDisposable

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Matthew Podwysocki | Powered by: GeeksWithBlogs.net