public SL600SDK CreateInstance() { lock (_syncObj) { if (_hModule == IntPtr.Zero) { _hModule = Win32Interop.LoadLibraryExW(_pathToDll, IntPtr.Zero, 0x00001000); if (_hModule == IntPtr.Zero) { Win32Interop.GetLastErrorAndThrow(); } } if (_thread == null) { _thread = new DispathcedThread(); } if (_functions == null) { _functions = new FunctionPointersContainer(_hModule); } var inst = new SL600SDK(_thread, _functions); inst.Disposed += Inst_Disposed; Interlocked.Increment(ref _refCounter); return(inst); } }
private void Release() { lock (_syncObj) { _thread.Dispose(); _thread = null; _functions = null; Win32Interop.FreeLibrary(_hModule); _hModule = IntPtr.Zero; } }
protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { // TODO: освободить управляемое состояние (управляемые объекты). } _thread = null; _functions = null; disposedValue = true; Disposed?.Invoke(this, new EventArgs()); } }
internal SL600SDK(DispathcedThread thread, FunctionPointersContainer functions) { _thread = thread; _functions = functions; }