public void ReleaseCOMProxy()
        {
            IEventBinding typeEvent = this as IEventBinding;

            if (null != typeEvent)
            {
                typeEvent.DisposeSinkHelper();
            }

            // remove himself from parent childlist
            if (null != _parentObject)
            {
                _parentObject.RemoveChildObject(this);
                _parentObject = null;
            }

            // finally release himself
            if (null != _underlyingObject)
            {
                if (_underlyingObject is ICustomAdapter)
                {
                    // enumerator
                    ICustomAdapter adapter = (ICustomAdapter)_underlyingObject;
                    Marshal.ReleaseComObject(adapter.GetUnderlyingObject());
                }
                else
                {
                    Marshal.ReleaseComObject(_underlyingObject);
                }
                _underlyingObject = null;
            }
        }
Esempio n. 2
0
 private static object AdapterGetUnderlyingObject(ICustomAdapter adapter)
 {
     try
     {
         return(adapter.GetUnderlyingObject());
     }
     catch (Exception exception)
     {
         DebugConsole.Default.WriteException(exception);
         throw;
     }
 }
Esempio n. 3
0
 private ICustomAdapter TryConvertToCustomAdapter()
 {
     try
     {
         ICustomAdapter adapter = _proxy as ICustomAdapter;
         return(adapter);
     }
     catch
     {
         // cast want throw an exception if rcw is already disconnected
         return(null);
     }
 }
Esempio n. 4
0
 public void ReleaseCOMProxy()
 {
     // release himself from COM Runtime System
     if (!Object.ReferenceEquals(_underlyingObject, null))
     {
         if (_isEnumerator)
         {
             ICustomAdapter adapter = _underlyingObject as ICustomAdapter;
             Marshal.ReleaseComObject(adapter.GetUnderlyingObject());
         }
         else
         {
             Marshal.ReleaseComObject(_underlyingObject);
         }
         Factory.RemoveObjectFromList(this);
         _underlyingObject = null;
     }
 }
Esempio n. 5
0
 private void ReleaseComObject()
 {
     if (_isEnumerator)
     {
         ICustomAdapter adapter = TryConvertToCustomAdapter();
         if (null != adapter)
         {
             object adapterUnderlyingObject = AdapterGetUnderlyingObject(adapter);
             MarshalReleaseComObject(adapterUnderlyingObject);
         }
         else
         {
             MarshalReleaseComObject(_proxy);
         }
     }
     else
     {
         MarshalReleaseComObject(_proxy);
     }
     _proxy = null;
 }
Esempio n. 6
0
        private List <ExplorerWindow> GetExplorerWindows(Func <SHDocVw.IWebBrowser2, List <ExplorerWindow>, bool> funcBreak)
        {
            var list = new List <ExplorerWindow>();

            Shell32.Shell        shell      = null;
            SHDocVw.ShellWindows win        = null;
            IEnumerator          enumerator = null;

            try
            {
                shell = new Shell32.Shell();
                win   = shell.Windows();

                enumerator = win.GetEnumerator();

                SHDocVw.IWebBrowser2 web = null;

                while (enumerator.MoveNext())
                {
                    web = enumerator.Current as SHDocVw.IWebBrowser2;
                    try
                    {
                        if (funcBreak(web, list))
                        {
                            break;
                        }
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                    finally
                    {
                        if (web != null)
                        {
                            Marshal.ReleaseComObject(web);
                        }
                    }
                }

                return(list);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                ICustomAdapter adapter = enumerator as ICustomAdapter;
                if (adapter != null)
                {
                    Marshal.ReleaseComObject(adapter.GetUnderlyingObject());
                }
                if (win != null)
                {
                    Marshal.ReleaseComObject(win);
                }
                if (shell != null)
                {
                    Marshal.ReleaseComObject(shell);
                }

                adapter    = null;
                enumerator = null;
                win        = null;
                shell      = null;

                // Application オブジェクトのガベージ コレクトを強制します。
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
            }
        }
 public CustomersApplicationService(ICustomerRepository customerRepository, ICustomAdapter customAdapter)
 {
     _customerRepository = customerRepository;
     _customAdapter      = customAdapter;
 }