Exemple #1
0
        public void OnAppActivate(int fActive, uint dwOtherThreadID)
        {
            if (fActive == 0)
            {
                int count = 0;

                using (lockObject.Lock())
                {
                    count = queuedActions.Count;

                    if (Thread.CurrentThread.ManagedThreadId != uiThread.ManagedThreadId)
                    {
                        return;
                    }
                }

                while (count > 0)
                {
                    GlobalCommandTargetAction queuedAction = null;

                    using (lockObject.Lock())
                    {
                        queuedAction = queuedActions.Peek();

                        if (queuedAction.DelayCount == 0)
                        {
                            queuedAction = queuedActions.Dequeue();
                        }
                        else
                        {
                            break;
                        }
                    }

                    if (queuedAction != null)
                    {
                        queuedAction.Action();
                    }

                    using (lockObject.Lock())
                    {
                        count = queuedActions.Count;
                    }
                }
            }
        }
Exemple #2
0
        public int FDoIdle(uint grfidlef)
        {
            GlobalCommandTargetAction        queuedAction     = null;
            List <GlobalCommandTargetAction> allQueuedActions = null;
            var idleFlags = (_OLEIDLEF)grfidlef;

            using (lockObject.Lock())
            {
                if (Thread.CurrentThread.ManagedThreadId != uiThread.ManagedThreadId)
                {
                    return(VSConstants.S_OK);
                }

                if (queuedActions.Count > 0)
                {
                    if (idleFlags == _OLEIDLEF.oleidlefAll)
                    {
                        allQueuedActions = queuedActions.ToList();

                        while (queuedActions.Count > 0)
                        {
                            queuedActions.Dequeue();
                        }
                    }
                    else
                    {
                        queuedAction = queuedActions.Peek();

                        if (queuedAction.DelayCount > 0)
                        {
                            queuedAction.DelayCount--;
                            queuedAction = null;
                        }
                        else
                        {
                            queuedAction = queuedActions.Dequeue();
                        }
                    }
                }

                if (whenActions.Count > 0)
                {
                    foreach (var whenAction in whenActions.ToList())
                    {
                        if (whenAction.WhenCallback())
                        {
                            whenActions.Remove(whenAction);
                        }
                    }
                }
            }

            if (allQueuedActions != null)
            {
                foreach (var action in allQueuedActions)
                {
                    action.Action();

                    if (action.Event != null)
                    {
                        action.Event.Set();
                    }
                }
            }
            else if (queuedAction != null)
            {
                queuedAction.Action();

                if (queuedAction.Event != null)
                {
                    queuedAction.Event.Set();
                }
            }

            return(VSConstants.S_OK);
        }