Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Closing COM-Interop Application

Closing COM-Interop Application

Scheduled Pinned Locked Moved C#
comquestioncsharp
8 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jurgen Jung
    wrote on last edited by
    #1

    I have a simple C#-(Windows-)Application. The Main-Form has two COM-Members. Working with this variables is ok, everything works as expected. When i close the application by the menu, i call Close() in the event-handler and everything is ok, but when i close by systemmenu or alt-f4 i got a com-leak. What is the reason, what is missing ?

    S 1 Reply Last reply
    0
    • J Jurgen Jung

      I have a simple C#-(Windows-)Application. The Main-Form has two COM-Members. Working with this variables is ok, everything works as expected. When i close the application by the menu, i call Close() in the event-handler and everything is ok, but when i close by systemmenu or alt-f4 i got a com-leak. What is the reason, what is missing ?

      S Offline
      S Offline
      SeMartens
      wrote on last edited by
      #2

      Hi, sorry for asking you, but what is a COM-leak? How does you know it is one? (Exception, error etc.?) Regards Sebastian

      It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.

      J 1 Reply Last reply
      0
      • S SeMartens

        Hi, sorry for asking you, but what is a COM-leak? How does you know it is one? (Exception, error etc.?) Regards Sebastian

        It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.

        J Offline
        J Offline
        Jurgen Jung
        wrote on last edited by
        #3

        At the end of the programm, INSIDE the COM-Component it is checked wether all references are "freed", this means if the refcounts are down to zero. The component is not only one single object, instead the library contains an object-hierarchy.

        S 1 Reply Last reply
        0
        • J Jurgen Jung

          At the end of the programm, INSIDE the COM-Component it is checked wether all references are "freed", this means if the refcounts are down to zero. The component is not only one single object, instead the library contains an object-hierarchy.

          S Offline
          S Offline
          SeMartens
          wrote on last edited by
          #4

          It is possible to "hook" into the event if Alt-F4 is called. Do you got a Forms-application? If yes you can register an event handler for FormClosing. Within this handler you can call the close-method for your COM.

          It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.

          J 1 Reply Last reply
          0
          • S SeMartens

            It is possible to "hook" into the event if Alt-F4 is called. Do you got a Forms-application? If yes you can register an event handler for FormClosing. Within this handler you can call the close-method for your COM.

            It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.

            J Offline
            J Offline
            Jurgen Jung
            wrote on last edited by
            #5

            If have tried Form_Closed and/or Form_Closing event to call Marshal.ReleaseCOMObject(). But it doesn't help,

            S 1 Reply Last reply
            0
            • J Jurgen Jung

              If have tried Form_Closed and/or Form_Closing event to call Marshal.ReleaseCOMObject(). But it doesn't help,

              S Offline
              S Offline
              SeMartens
              wrote on last edited by
              #6

              Hmmmm... Other way could be to go into the Dispose()-method of the form and to call the release-method there.

              It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.

              J 1 Reply Last reply
              0
              • S SeMartens

                Hmmmm... Other way could be to go into the Dispose()-method of the form and to call the release-method there.

                It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.

                J Offline
                J Offline
                Jurgen Jung
                wrote on last edited by
                #7

                Thanks for the tip. In the ...Designer.cs i modified Dispose

                    /// <summary>
                    /// Clean up any resources being used.
                    /// </summary>
                    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
                    protected override void Dispose(bool disposing)
                    {
                        if (disposing && (components != null))
                        {
                            components.Dispose();
                
                            if (m\_Session != null)
                            {
                                while (true)
                                {
                                    if (Marshal.ReleaseComObject(m\_Session) <= 0)
                                    {
                                        m\_Session = null;
                                        break;
                                    }
                                }
                            }
                            if (m\_System != null)
                            {
                                while (true)
                                {
                                    if (Marshal.ReleaseComObject(m\_System) <= 0)
                                    {
                                        m\_System = null;
                                        break;
                                    }
                                }
                            }
                
                        }
                        base.Dispose(disposing);
                    }
                

                but it doesnt't help, because the code isn't called at all, have i misunderstood you ?

                S 1 Reply Last reply
                0
                • J Jurgen Jung

                  Thanks for the tip. In the ...Designer.cs i modified Dispose

                      /// <summary>
                      /// Clean up any resources being used.
                      /// </summary>
                      /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
                      protected override void Dispose(bool disposing)
                      {
                          if (disposing && (components != null))
                          {
                              components.Dispose();
                  
                              if (m\_Session != null)
                              {
                                  while (true)
                                  {
                                      if (Marshal.ReleaseComObject(m\_Session) <= 0)
                                      {
                                          m\_Session = null;
                                          break;
                                      }
                                  }
                              }
                              if (m\_System != null)
                              {
                                  while (true)
                                  {
                                      if (Marshal.ReleaseComObject(m\_System) <= 0)
                                      {
                                          m\_System = null;
                                          break;
                                      }
                                  }
                              }
                  
                          }
                          base.Dispose(disposing);
                      }
                  

                  but it doesnt't help, because the code isn't called at all, have i misunderstood you ?

                  S Offline
                  S Offline
                  SeMartens
                  wrote on last edited by
                  #8

                  No, you didn't misunderstood me :) Hmm... now i'm just at a loss. Normally, if you press Alt-F4 the FormClosing-event should be called. At least Dispose...

                  It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups