Dispose MUST be called from the client and not from the serviced component...

 

There is a requirement for clients of COM+ Serviced Components to call dispose on the component.  If you do not do this, it will not shut down.  When you inherit from servicedcomponent, you also inherit from IDisposable.  However, the client MUST call the dispose method explicitly to properly clean up the object instance.

 

FIX: A COM+ application that uses the global interface table (GIT) may deadlock
http://support.microsoft.com/kb/298014/

FIX: Slow performance, deadlocks, and memory leaks may occur when applications do not call the Dispose method on all instances of the ServicedComponent class in the .NET Framework
http://support.microsoft.com/kb/875503/en-us
 

In unmanaged C++:

-----------------

 

In C++ get the IDispatch pointer and call this...

 

. . .

            IDispatch* objDispatch;

            ptrNone[i].QueryInterface(&objDispatch);

            hr = DoDispose(objDispatch);

            objDispatch->Release();

            ptrNone[i].Release();

 

. . .

 

HRESULT DoDispose(IDispatch* objDispatch)

{

      HRESULT hr = S_OK;

      CComVariant vParams,vResult;

      unsigned int iError = 0;

      EXCEPINFO pErr;

      ZeroMemory(&pErr,sizeof(EXCEPINFO));

           

      DISPPARAMS params;

      params.cArgs = 0;

      params.cNamedArgs = 0;

      params.rgdispidNamedArgs = NULL;

           

      DISPID dispid;

            OLECHAR* name = L"Dispose";

      HRESULT dispHR = objDispatch->GetIDsOfNames

 

(IID_NULL,&name,1,LOCALE_SYSTEM_DEFAULT,&dispid);

 

      // Make the call to the "Dispose" method

      hr = objDispatch->Invoke(dispid,

                  IID_NULL,

                  LOCALE_SYSTEM_DEFAULT,

                  DISPATCH_METHOD,

                  &params,

                  &vResult,

                  &pErr,

                  &iError);

 

      return hr;

}

 

 

In C#/managed code:

-------------------

Here is a sample of what C# would do for the call.  In this case DoStuff will do an Exchange Powershell call (implementation not shown):

 

  MyServicedCOM.MyServicedCOMponent abc = new   MyServicedCOM.MyServicedCOMponent();

  iRet = abc.DoStuff(sServerName, sSGName);

  IDisposable idsp = abc as IDisposable;

  idsp.Dispose();

 

To check for shut-down:

-----------------------

One other thing that should help to illuminate it:  In Component Services, find your

application, and expand all the way down to the components folder.  Find this component and

right click, choose properties.  On the activation tab, check the “Component supports events and

statistics” checkbox.

 

Close properties, then select the components folder for you application.  Right click on the folder and change the view to “Status”.  This will show you if the object is running and when/if it shuts down.

 

For further information on PowerShell, please visit the link below:

------------------------------------------------------------------------------

 

Links on Common PowerShell Automation Questions

http://blogs.msdn.com/webdav_101/archive/2008/09/26/links-on-common-powershell-automation-questions.aspx