protected virtual void Dispose(bool disposing) { if (disposing) { _stillRunning = false; int sessionCount = 0; // NOTE: This is done in a way to avoid possible situations when the OpenALHardwareDeviceSession is already being dispose in another thread but doesn't hold the lock and tries to Unregister. do { lock (_lock) { if (_sessions.Count == 0) { break; } OpenALHardwareDeviceSession session = _sessions[_sessions.Count - 1]; session.Dispose(); sessionCount = _sessions.Count; } }while (sessionCount > 0); ALC.DestroyContext(_context); ALC.CloseDevice(_device); } }
protected virtual void Dispose(bool disposing) { if (disposing) { lock (_lock) { _stillRunning = false; _updaterThread.Join(); // Loop against all sessions to dispose them (they will unregister themself) while (_sessions.Count > 0) { OpenALHardwareDeviceSession session = _sessions[0]; session.Dispose(); } } _context.Dispose(); } }