/// <summary> /// Cleans up the COM object references. /// </summary> /// <param name="disposing"> /// <see langword="true"/> if this was called from the /// <see cref="IDisposable"/> interface. /// </param> protected virtual void Dispose(bool disposing) { if (disposing) { _owner = null; _unmappedEventKeys = null; if (null != _events) { _events.Dispose(); _events = null; } } if (null != _connectionPoint) { if (0 != _connectionCookie) { _connectionPoint.Unadvise(_connectionCookie); _connectionCookie = 0; } while (Marshal.ReleaseComObject(_connectionPoint) > 0) { ; } _connectionPoint = null; } }
public void CleanupControl() { if (IsCreated) { if (cookie != -1) { icp.Unadvise(cookie); cookie = -1; } site.CloseDocument(); site.Dispose(); site = null; this.m_htmldoc = null; } }
#pragma warning restore 618 #region Implementation of IObjectWithSite int IObjectWithSite.SetSite(object site) { #if DEBUG // launch debugger when in Debug build Debugger.Launch(); #endif if (site != null) { browser = (IWebBrowser2)site; // can't simply subscribe to OnBeforeNavigate2 from .NET - https://support.microsoft.com/en-us/kb/325079?wa=wsignin1.0 #pragma warning disable 618 UCOMIConnectionPointContainer icpc = (UCOMIConnectionPointContainer)site; #pragma warning restore 618 Guid g = typeof(DWebBrowserEvents).GUID; icpc.FindConnectionPoint(ref g, out icp); icp.Advise(this, out cookie); ((DWebBrowserEvents2_Event)browser).DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete); ((DWebBrowserEvents2_Event)browser).DownloadBegin += new DWebBrowserEvents2_DownloadBeginEventHandler(this.OnDownloadBegin); ((DWebBrowserEvents2_Event)browser).DownloadComplete += new DWebBrowserEvents2_DownloadCompleteEventHandler(this.OnDownloadComplete); } else { icp.Unadvise(cookie); ((DWebBrowserEvents2_Event)browser).DocumentComplete -= new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete); ((DWebBrowserEvents2_Event)browser).DownloadComplete -= new DWebBrowserEvents2_DownloadCompleteEventHandler(this.OnDownloadComplete); browser = null; } return(0); }
// Disconnect from ActiveX event source void Disconnect() { System.Threading.Monitor.Enter(this); try { if (EventSinkHelper != null) { ConnectionPoint.Unadvise(EventSinkHelper.Cookie); } ConnectionPoint = null; EventSinkHelper = null; } catch { } System.Threading.Monitor.Exit(this); }
/// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose(bool disposing) { if (disposing) { if (components != null) { components.Dispose(); } if (myCookie != 0) { ias.DeactivateAllEvents(); icp.Unadvise(myCookie); } } base.Dispose(disposing); }
private void ReturnToPool() { if (_signaled) { if (null != _pooledObject && null != _pool) { _pool.PutNewObject(_pooledObject); _pool = null; _pooledObject = null; } if (0 != _cookie && null != _point) { _point.Unadvise(_cookie); _point = null; _cookie = 0; } } }
private void ReturnToPool() { if (_signaled) { if (null != _connection && null != _pool) { _pool.PutNewConnection(_connection); _pool = null; _connection = null; } if (0 != _cookie && null != _point) { _point.Unadvise(_cookie); _point = null; _cookie = 0; } } }
/// <summary> /// Disconnects from Allsrv /// </summary> public void Disconnect() { if (_cookie != 0) { _connector = null; try { _session.DeactivateAllEvents(); } catch (Exception) { // An exception will be thrown if the session has already been detached // Ignore it! TagTrace.WriteLine(TraceLevel.Verbose, "Error while attempting to detach session. Session is already destroyed."); } finally { _session = null; } try { _icp.Unadvise(_cookie); } catch (Exception e) { // Ignore exceptions if we're already detached TagTrace.WriteLine(TraceLevel.Verbose, "Error while disposing session. Session is already disposed.", e.Message); } finally { _cookie = 0; } } }
/// <summary> /// Ie_s the document complete. /// </summary> /// <param name="pDisp">P disp.</param> /// <param name="URL">URL.</param> private void ie_DocumentComplete(object pDisp, ref object URL) { if (m_dwCookie != 0) { pConPt.Unadvise(m_dwCookie); } //Funky, yes, with a reason: http://support.microsoft.com/?id=811645 // Help from http://www.eggheadcafe.com/ng/microsoft.public.dotnet.framework.sdk/post21853543.asp // We are going to sink the event here by using COM connection point. doc = (HTMLDocument)ie.Document; // I am going to QueryInterface UCOMConnectionPointContainer of the WebBrowser Control UCOMIConnectionPointContainer pConPtCon = (UCOMIConnectionPointContainer)doc; // Get access to the IConnectionPoint pointer. // UCOMIConnectionPoint pConPt; // Get the GUID of the HTMLDocumentEvents2 Guid guid = typeof(HTMLDocumentEvents2).GUID; pConPtCon.FindConnectionPoint(ref guid, out pConPt); // define your event handler class IEHTMLDocumentEvents d = new IEHTMLDocumentEvents(this); pConPt.Advise(d, out m_dwCookie); }
public string ExecuteSqlServerPackage(int iBuyerCompanyID, string strFromDate, string strToDate, string strType) { string strMessage = ""; UCOMIConnectionPointContainer CnnctPtCont = null; UCOMIConnectionPoint CnnctPt = null; PackageEventsSink PES = null; int iCookie = 0; try { package = new Package2Class(); CnnctPtCont = (UCOMIConnectionPointContainer)package; PES = new PackageEventsSink(); Guid guid = new Guid("10020605-EB1C-11CF-AE6E-00AA004A34D5"); CnnctPtCont.FindConnectionPoint(ref guid, out CnnctPt); CnnctPt.Advise(PES, out iCookie); object pVarPersistStgOfHost = null; package.LoadFromSQLServer(serverName, serverUsername, serverPassword, DTSSQLServerStorageFlags.DTSSQLStgFlag_Default, null, null, null, packageName, ref pVarPersistStgOfHost); foreach (GlobalVariable global in package.GlobalVariables) { try { if (global.Name.Equals("BuyerCompanyID")) { package.GlobalVariables.Remove(global.Name); } if (global.Name.Equals("FromDate")) { package.GlobalVariables.Remove(global.Name); } if (global.Name.Equals("ToDate")) { package.GlobalVariables.Remove(global.Name); } } catch (Exception ex) { strMessage = strMessage + ex.Message + Environment.NewLine; } } //Read all the global variables that are of type string package.GlobalVariables.AddGlobalVariable("BuyerCompanyID", iBuyerCompanyID); package.GlobalVariables.AddGlobalVariable("FromDate", strFromDate); package.GlobalVariables.AddGlobalVariable("ToDate", strToDate); package.Execute(); package.UnInitialize(); package = null; CnnctPt.Unadvise(iCookie); //a connection that is created by IConnectionPoint.Advise must be closed by calling IConnectionPoint.Unadvise to avoid a memory leak strMessage = strMessage + "CSV Files generated successfully through DTS package." + Environment.NewLine; } catch (System.Runtime.InteropServices.COMException ex) { strMessage = strMessage + ex.Message + Environment.NewLine; package.UnInitialize(); package = null; CnnctPt.Unadvise(iCookie); } catch (Exception ex) { strMessage = strMessage + ex.Message + Environment.NewLine; package.UnInitialize(); package = null; CnnctPt.Unadvise(iCookie); } return(strMessage); }