public void Dispose() { try { if (_opcServer != null) { foreach (var grp in _groups) { _opcServer.RemoveGroup(grp.Key, true); grp.Value.Dispose(); } _groups.Clear(); } if (_shutDownPoint != null) { if (_shutDownCookie != 0) { _shutDownPoint.Unadvise(_shutDownCookie); } Marshal.ReleaseComObject(_shutDownPoint); } if (_opcServerObj != null) { Marshal.ReleaseComObject(_opcServerObj); } } catch (Exception e) { ShutdownRequest(e.Message); } _opcServerObj = null; _opcServer = null; _shutDownPoint = null; _shutDownCookie = 0; }
/// <summary> /// 断开PLC的连接 /// </summary> /// <returns></returns> public string DisConnection() { string errText = string.Empty; try { if (IOPCSyncIO2Obj != null) { Marshal.ReleaseComObject(IOPCSyncIO2Obj); IOPCSyncIO2Obj = null; } ServerObj.RemoveGroup(pSvrGroupHandle, 0); if (IOPCGroupStateMgtObj != null) { Marshal.ReleaseComObject(IOPCGroupStateMgtObj); IOPCGroupStateMgtObj = null; } if (MyobjGroup1 != null) { Marshal.ReleaseComObject(MyobjGroup1); MyobjGroup1 = null; } if (ServerObj != null) { Marshal.ReleaseComObject(ServerObj); ServerObj = null; } } catch (System.Exception error) { errText = error.Message.ToString().Trim(); } return(errText); }
/// <summary> /// Releases unmanaged resources held by the object. /// </summary> protected override void Dispose(bool disposing) { if (!m_disposed) { lock (this) { if (disposing) { // Release managed resources. if (m_server != null) { // release all groups. foreach (Subscription subscription in subscriptions_.Values) { string methodName = "IOPCServer.RemoveGroup"; // remove subscription from server. try { TsCDaSubscriptionState state = subscription.GetState(); if (state != null) { IOPCServer server = BeginComCall <IOPCServer>(methodName, true); server?.RemoveGroup((int)state.ServerHandle, 0); } } catch (Exception e) { ComCallError(methodName, e); } finally { EndComCall(methodName); } // dispose of the subscription object (disconnects all subscription connections). subscription.Dispose(); } // clear subscription table. subscriptions_.Clear(); } } // Release unmanaged resources. // Set large fields to null. if (m_server != null) { // release the COM server. Technosoftware.DaAeHdaClient.Com.Interop.ReleaseServer(m_server); m_server = null; } } // Call Dispose on your base class. m_disposed = true; } base.Dispose(disposing); }
private void InternalRemove(bool force) { if (!(callbackConnectionPoint == null)) { if (callbackCookie != 0) { callbackConnectionPoint.Unadvise(callbackCookie); callbackCookie = 0; } int rc = Marshal.ReleaseComObject(callbackConnectionPoint); callbackConnectionPoint = null; } if (!(opcGroupObject == null)) { int rc = Marshal.ReleaseComObject(opcGroupObject); opcGroupObject = null; } if (!(parentServer == null)) { if (!statePublic) { parentServer.RemoveGroup(stateHandleServer, force); } parentServer = null; } stateHandleServer = 0; }
public void Remove(bool p_Force) { if (m_CallbackPoint != null) { if (m_CallbackCookie != 0) { m_CallbackPoint.Unadvise(m_CallbackCookie); m_CallbackCookie = 0; } Marshal.ReleaseComObject(m_CallbackPoint); m_CallbackPoint = null; } m_PointContainer = null; m_IfItems = null; m_IfSync = null; m_IfAsync = null; if (m_IfMgt != null) { Marshal.ReleaseComObject(m_IfMgt); m_IfMgt = null; } if (m_IfServer != null) { if (!m_State.Public) { m_IfServer.RemoveGroup(m_State.HandleServer, p_Force); } m_IfServer = null; } m_State.HandleServer = 0; }
public void unloadcomobjects() { Marshal.ReleaseComObject(pIOPCSyncIO); pIOPCSyncIO = null; pIOPCServer.RemoveGroup(nSvrGroupID, 0); Marshal.ReleaseComObject(pobjGroup1); pobjGroup1 = null; }
/*------------------------------------------------------ * Disconnect OPC Server * * (ret) True OK * False NG * ------------------------------------------------------*/ public bool Disconnect() { if (m_OPCServer == null) { return(true); } int ret; try { Unadvise(); if (m_OPCGroup != null) { ret = Marshal.ReleaseComObject(m_OPCGroup); m_OPCGroup = null; } if (m_OPCGroup2 != null) { ret = Marshal.ReleaseComObject(m_OPCGroup2); m_OPCGroup2 = null; } if (m_OPCConnPoint != null) { ret = Marshal.ReleaseComObject(m_OPCConnPoint); m_OPCConnPoint = null; } // 2011/11/14 シャットダウンイベントを受けれるようにする ( if (m_iShutdownConnectionCookie != 0) { m_OpcShutdownConnectionPoint.Unadvise(m_iShutdownConnectionCookie); } m_iShutdownConnectionCookie = 0; if (m_OpcShutdownConnectionPoint != null) { Marshal.ReleaseComObject(m_OpcShutdownConnectionPoint); m_OpcShutdownConnectionPoint = null; } // 2011/11/14 シャットダウンイベントを受けれるようにする ) if (m_iServerGroup != 0) // 06/10/19 Fixed the timing of 'RemoveGroup'. { // m_OPCServer.RemoveGroup(m_iServerGroup, 0); // m_iServerGroup = 0; // } // ret = Marshal.ReleaseComObject(m_OPCServer); m_OPCServer = null; m_bConnect = false; return(true); } catch (Exception exc) { MessageBox.Show(exc.ToString(), "Disconnect"); m_bConnect = false; return(false); } }
/// <summary> /// Cancels a subscription and releases all resources allocated for it. /// </summary> /// <param name="subscription">The subscription to cancel.</param> public void CancelSubscription(ITsCDaSubscription subscription) { if (subscription == null) { throw new ArgumentNullException(nameof(subscription)); } lock (this) { if (server_ == null) { throw new NotConnectedException(); } string methodName = "IOPCServer.RemoveGroup"; // validate argument. if (!typeof(Subscription).IsInstanceOfType(subscription)) { throw new ArgumentException("Incorrect object type.", nameof(subscription)); } // get the subscription state. TsCDaSubscriptionState state = subscription.GetState(); if (!subscriptions_.ContainsKey(state.ServerHandle)) { throw new ArgumentException("Handle not found.", nameof(subscription)); } subscriptions_.Remove(state.ServerHandle); // release all subscription resources. subscription.Dispose(); // invoke COM method. try { IOPCServer server = BeginComCall <IOPCServer>(methodName, true); server.RemoveGroup((int)state.ServerHandle, 0); if (DCOMCallWatchdog.IsCancelled) { throw new Exception($"{methodName} call was cancelled due to response timeout"); } } catch (Exception e) { ComCallError(methodName, e); throw Utilities.Interop.CreateException(methodName, e); } finally { EndComCall(methodName); } } }
/// <summary> /// 断开连接OpcServer /// </summary> public void OpcDisConnect() { foreach (var item in OpcGroups) { try { item.Value.Dispose(); opcServer.RemoveGroup(item.Value.ServerGroupHandle, 0); } catch (Exception) { } } try { if (dwCookie != 0) { connectionPoint.Unadvise(dwCookie); dwCookie = 0; } } catch (Exception) { dwCookie = 0; } try { if (connectionPoint != null) { Marshal.ReleaseComObject(connectionPoint); connectionPoint = null; } if (connectionPointContainer != null) { Marshal.ReleaseComObject(connectionPointContainer); connectionPointContainer = null; } if (opcServer != null) { Marshal.ReleaseComObject(opcServer);//减与指定的 COM 对象关联的运行时可调用包装器 (RCW) 的引用计数。 } } finally { if (opcServer != null) { opcServer = null; } if (_opcServer != null) { _opcServer = null; } } }
/// <summary> /// 断开PLC的连接 /// </summary> /// <returns></returns> public string DisConnection() { string errText = string.Empty; try { if (dwCookie != 0) { pIConnectionPoint.Unadvise(dwCookie); dwCookie = 0; } // Free unmanaged code Marshal.ReleaseComObject(pIConnectionPoint); pIConnectionPoint = null; Marshal.ReleaseComObject(pIConnectionPointContainer); pIConnectionPointContainer = null; if (IOPCAsyncIO2Obj != null) { Marshal.ReleaseComObject(IOPCAsyncIO2Obj); IOPCAsyncIO2Obj = null; } ServerObj.RemoveGroup(pSvrGroupHandle, 0); if (IOPCGroupStateMgtObj != null) { Marshal.ReleaseComObject(IOPCGroupStateMgtObj); IOPCGroupStateMgtObj = null; } if (MyobjGroup1 != null) { Marshal.ReleaseComObject(MyobjGroup1); MyobjGroup1 = null; } if (ServerObj != null) { Marshal.ReleaseComObject(ServerObj); ServerObj = null; } } catch (System.Exception error) { errText = error.Message.ToString().Trim(); } return(errText); }
/// <summary> </summary> /// <exception cref="Exception">throws and forwards any exception (with short error description)</exception> private void removeGroup() { if (m_grpSrvHndl != 0) { if (m_OPCServer != null) { try { m_OPCServer.RemoveGroup(m_grpSrvHndl, Convert.ToInt32(true)); m_grpSrvHndl = 0; } catch (Exception) { throw; } } } }
/// <summary> /// Removes a group. /// </summary> public void RemoveGroup(int groupHandle) { string methodName = "IOPCServer.RemoveGroup"; try { IOPCServer server = BeginComCall <IOPCServer>(methodName, true); server.RemoveGroup(groupHandle, 0); } catch (Exception e) { ComUtils.TraceComError(e, methodName); return; } finally { EndComCall(methodName); } }
public void Remove(bool bForce) { ifItems = null; ifSync = null; if (!(ifMgt == null)) { int rc = Marshal.ReleaseComObject(ifMgt); ifMgt = null; } if (!(ifServer == null)) { if (!state.Public) { ifServer.RemoveGroup(state.HandleServer, bForce); } ifServer = null; } state.HandleServer = 0; }