public void Open(RegistryHive hive, string serverName)
        {
            this.m_openCalled = true;
            int remoteRegistryTimeoutInMsec = RegistryParameters.RemoteRegistryTimeoutInMsec;

            RemoteRegistryBaseKey.AsyncOpenTask asyncOpenTask = new RemoteRegistryBaseKey.AsyncOpenTask(this.DoOpen);
            this.m_asyncRefCount = 2;
            IAsyncResult asyncResult     = asyncOpenTask.BeginInvoke(hive, serverName, new AsyncCallback(RemoteRegistryBaseKey.OpenCompletion), asyncOpenTask);
            WaitHandle   asyncWaitHandle = asyncResult.AsyncWaitHandle;

            if (!asyncWaitHandle.WaitOne(remoteRegistryTimeoutInMsec, false) && Interlocked.Decrement(ref this.m_asyncRefCount) > 0)
            {
                throw new RemoteRegistryTimedOutException(serverName, remoteRegistryTimeoutInMsec / 1000);
            }
            asyncOpenTask.EndInvoke(asyncResult);
        }
        private static void OpenCompletion(IAsyncResult ar)
        {
            RemoteRegistryBaseKey.AsyncOpenTask asyncOpenTask = (RemoteRegistryBaseKey.AsyncOpenTask)ar.AsyncState;
            RemoteRegistryBaseKey remoteRegistryBaseKey       = (RemoteRegistryBaseKey)asyncOpenTask.Target;

            if (Interlocked.Decrement(ref remoteRegistryBaseKey.m_asyncRefCount) > 0)
            {
                return;
            }
            Exception ex = null;

            try
            {
                asyncOpenTask.EndInvoke(ar);
            }
            catch (IOException ex2)
            {
                ex = ex2;
            }
            catch (SecurityException ex3)
            {
                ex = ex3;
            }
            catch (UnauthorizedAccessException ex4)
            {
                ex = ex4;
            }
            finally
            {
                if (ex != null)
                {
                    ExTraceGlobals.StateTracer.TraceDebug <string>((long)remoteRegistryBaseKey.GetHashCode(), "RemoteRegistryBaseKey hit exception after being abandoned: {0}", ex.Message);
                }
                remoteRegistryBaseKey.Dispose();
            }
        }