Пример #1
0
        private void Dispose()
        {
            _cancelHandle?.Dispose();

            if (_gcHandle.IsAllocated)
            {
                _gcHandle.Free();
            }
        }
Пример #2
0
        private void RunCallback(object o)
        {
            if (!_runCallbackCalled)
            {
                NetEventSource.Fail(null, "RunCallback called without setting runCallbackCalled!");
            }

            // If OnAppDomainUnload beats us to the lock, do nothing: the AppDomain is going down soon anyways.
            // Otherwise, wait until the call to CancelMibChangeNotify2 is done before giving it up.
            lock (s_pendingNotifications)
            {
                if (Environment.HasShutdownStarted)
                {
                    return;
                }

#if DEBUG
                bool successfullyRemoved = s_pendingNotifications.Remove(this);
                if (!successfullyRemoved)
                {
                    NetEventSource.Fail(null, "RunCallback for a TeredoHelper which is not in s_pendingNotifications!");
                }
#else
                s_pendingNotifications.Remove(this);
#endif

                if ((_cancelHandle == null || _cancelHandle.IsInvalid))
                {
                    NetEventSource.Fail(null, "Invalid cancelHandle in RunCallback");
                }

                _cancelHandle.Dispose();
            }

            _callback.Invoke(_state);
        }