- .NET API: ControlObject implements IDisposable interface

This commit is contained in:
Michael Zillgith 2017-10-28 15:52:49 +02:00
parent 5fb8c5b984
commit 0c09385462
2 changed files with 17 additions and 8 deletions

View file

@ -104,7 +104,7 @@ namespace IEC61850
/// <summary> /// <summary>
/// Control object. /// Control object.
/// </summary> /// </summary>
public class ControlObject public class ControlObject : IDisposable
{ {
[DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)]
private static extern LastApplErrorInternal ControlObjectClient_getLastApplError(IntPtr self); private static extern LastApplErrorInternal ControlObjectClient_getLastApplError(IntPtr self);
@ -183,12 +183,6 @@ namespace IEC61850
ControlObjectClient_setCommandTerminationHandler(controlObject, intCommandTerminationHandler, controlObject); ControlObjectClient_setCommandTerminationHandler(controlObject, intCommandTerminationHandler, controlObject);
} }
~ControlObject ()
{
if (this.controlObject != System.IntPtr.Zero)
ControlObjectClient_destroy(controlObject);
}
/// <summary> /// <summary>
/// Gets the control model. /// Gets the control model.
/// </summary> /// </summary>
@ -443,6 +437,18 @@ namespace IEC61850
this.commandTerminationHandlerParameter = parameter; this.commandTerminationHandlerParameter = parameter;
} }
protected virtual void Dispose(bool disposing) {
if (this.controlObject != System.IntPtr.Zero) {
ControlObjectClient_destroy (controlObject);
this.controlObject = System.IntPtr.Zero;
}
}
public void Dispose() {
Dispose (true);
}
} }
} }

View file

@ -86,7 +86,10 @@ namespace control
Thread.Sleep(1000); Thread.Sleep(1000);
} }
con.Abort(); // has to be called before IedConnection dispose method!
control.Dispose();
con.Abort();
} }
catch (IedConnectionException e) catch (IedConnectionException e)
{ {