private TrackingListener GetListenerFromWRCache(Guid instanceId)
        {
            WeakReference    reference = null;
            TrackingListener target    = null;

            lock (this._listenerLock)
            {
                if (!this._listeners.TryGetValue(instanceId, out reference))
                {
                    throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, ExecutionStringManager.ListenerNotInCache, new object[] { instanceId }));
                }
                target = reference.Target as TrackingListener;
                if (target == null)
                {
                    throw new ObjectDisposedException(string.Format(CultureInfo.InvariantCulture, ExecutionStringManager.ListenerNotInCacheDisposed, new object[] { instanceId }));
                }
            }
            return(target);
        }
        private void WorkflowExecutorInitializing(object sender, WorkflowRuntime.WorkflowExecutorInitializingEventArgs e)
        {
            if (sender == null)
            {
                throw new ArgumentNullException("sender");
            }
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }
            if (!typeof(WorkflowExecutor).IsInstanceOfType(sender))
            {
                throw new ArgumentException("sender");
            }
            WorkflowExecutor skedExec = (WorkflowExecutor)sender;

            skedExec.WorkflowExecutionEvent += new EventHandler <WorkflowExecutor.WorkflowExecutionEventArgs>(this.WorkflowExecutionEvent);
            TrackingCallingState   trackingCallingState = skedExec.TrackingCallingState;
            TrackingListenerBroker broker = (TrackingListenerBroker)skedExec.RootActivity.GetValue(WorkflowExecutor.TrackingListenerBrokerProperty);

            if (broker != null)
            {
                broker.ReplaceServices(skedExec.WorkflowRuntime.TrackingServiceReplacement);
            }
            TrackingListener target    = null;
            WeakReference    reference = null;

            if (e.Loading)
            {
                bool flag = false;
                lock (this._listenerLock)
                {
                    flag = this._listeners.TryGetValue(skedExec.InstanceId, out reference);
                }
                if (flag)
                {
                    try
                    {
                        target = reference.Target as TrackingListener;
                    }
                    catch (InvalidOperationException)
                    {
                    }
                }
                if (target != null)
                {
                    target.Broker = broker;
                    goto Label_01C8;
                }
                target = this.GetTrackingListener(skedExec.WorkflowDefinition, skedExec, broker);
                if (target == null)
                {
                    goto Label_01C8;
                }
                if (reference != null)
                {
                    reference.Target = target;
                    goto Label_01C8;
                }
                lock (this._listenerLock)
                {
                    this._listeners.Add(skedExec.ID, new WeakReference(target));
                    goto Label_01C8;
                }
            }
            target = this.GetTrackingListener(skedExec.WorkflowDefinition, skedExec);
            if (target != null)
            {
                skedExec.RootActivity.SetValue(WorkflowExecutor.TrackingListenerBrokerProperty, target.Broker);
                lock (this._listenerLock)
                {
                    this._listeners.Add(skedExec.ID, new WeakReference(target));
                    goto Label_01C8;
                }
            }
            skedExec.RootActivity.SetValue(WorkflowExecutor.TrackingListenerBrokerProperty, new TrackingListenerBroker());
Label_01C8:
            if (target != null)
            {
                skedExec.WorkflowExecutionEvent += new EventHandler <WorkflowExecutor.WorkflowExecutionEventArgs>(target.WorkflowExecutionEvent);
            }
        }