Click here to Skip to main content
15,851,319 members
Home / Discussions / C#
   

C#

 
GeneralRe: Destructor peculiarity Pin
Pete O'Hanlon23-Oct-09 3:25
subeditorPete O'Hanlon23-Oct-09 3:25 
GeneralRe: Destructor peculiarity Pin
Gideon Engelberth23-Oct-09 8:47
Gideon Engelberth23-Oct-09 8:47 
GeneralRe: Destructor peculiarity Pin
DaveyM6923-Oct-09 10:44
professionalDaveyM6923-Oct-09 10:44 
GeneralRe: Destructor peculiarity Pin
DaveyM6923-Oct-09 10:52
professionalDaveyM6923-Oct-09 10:52 
GeneralRe: Destructor peculiarity Pin
cmk23-Oct-09 6:21
cmk23-Oct-09 6:21 
GeneralRe: Destructor peculiarity Pin
DaveyM6923-Oct-09 9:10
professionalDaveyM6923-Oct-09 9:10 
GeneralRe: Destructor peculiarity Pin
DaveyM6923-Oct-09 10:48
professionalDaveyM6923-Oct-09 10:48 
AnswerRe: Destructor peculiarity Pin
Gideon Engelberth23-Oct-09 8:55
Gideon Engelberth23-Oct-09 8:55 
I'd say you are getting lucky.

It seems to me that you have the finalizer in the wrong place. The Manager does not directly own any unmanaged resources. Since the Port class does directly own the unmanaged resources (from the way you describe it), it should be Disposable and have a finalizer that calls Dispose(false) as per the Dispose pattern. Then it does not matter what order things get finalized in by the GC. Port would look something like this:

public class Port : IDisposable
{

   ~Port()
   {
      Dispose(false);
   }

   public void IDisposable.Dispose()
   {
        Dispose(true);
        GC.SupressFinalize(this);
   }
   
   private bool alreadyDisposed;
   protected void Dispose(bool disposing)
   {
      if (!alreadyDisposed)
      {
         if (disposing)
         {
            //clean up managed
         }

         //always clean up unmanaged
         
         alreadyDisposed = true;
      }
   }

   public void Close()
   {
      Dispose();
   }

   //other class code here
}

GeneralRe: Destructor peculiarity Pin
DaveyM6923-Oct-09 10:40
professionalDaveyM6923-Oct-09 10:40 
AnswerRe: Destructor peculiarity Pin
Luc Pattyn27-Oct-09 4:36
sitebuilderLuc Pattyn27-Oct-09 4:36 
GeneralRe: Destructor peculiarity Pin
DaveyM6927-Oct-09 8:04
professionalDaveyM6927-Oct-09 8:04 
GeneralRe: Destructor peculiarity Pin
Luc Pattyn27-Oct-09 8:09
sitebuilderLuc Pattyn27-Oct-09 8:09 
GeneralRe: Destructor peculiarity Pin
DaveyM6927-Oct-09 11:45
professionalDaveyM6927-Oct-09 11:45 
GeneralRe: Destructor peculiarity Pin
Luc Pattyn27-Oct-09 12:17
sitebuilderLuc Pattyn27-Oct-09 12:17 
GeneralRe: Destructor progress report 1 Pin
Luc Pattyn27-Oct-09 18:20
sitebuilderLuc Pattyn27-Oct-09 18:20 
GeneralRe: Destructor progress report 1 Pin
DaveyM6928-Oct-09 9:58
professionalDaveyM6928-Oct-09 9:58 
GeneralRe: Destructor progress report 1 Pin
Luc Pattyn28-Oct-09 10:54
sitebuilderLuc Pattyn28-Oct-09 10:54 
GeneralRe: Destructor progress report 1 Pin
DaveyM6928-Oct-09 11:52
professionalDaveyM6928-Oct-09 11:52 
GeneralRe: Destructor progress report 1 Pin
DaveyM6928-Oct-09 23:19
professionalDaveyM6928-Oct-09 23:19 
GeneralRe: Destructor progress report 1 Pin
DaveyM6928-Oct-09 10:35
professionalDaveyM6928-Oct-09 10:35 
QuestionTheading problem Pin
Rick van Woudenberg23-Oct-09 1:52
Rick van Woudenberg23-Oct-09 1:52 
AnswerRe: Theading problem Pin
Not Active23-Oct-09 3:49
mentorNot Active23-Oct-09 3:49 
Questionneed some quick help thx : how can i access and open form2 from form1 menu item Pin
KIM K23-Oct-09 1:48
KIM K23-Oct-09 1:48 
AnswerRe: need some quick help thx : how can i access and open form2 from form1 menu item Pin
nagendrathecoder23-Oct-09 1:55
nagendrathecoder23-Oct-09 1:55 
AnswerRe: need some quick help thx : how can i access and open form2 from form1 menu item Pin
Rick van Woudenberg23-Oct-09 1:57
Rick van Woudenberg23-Oct-09 1:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.