예제 #1
0
        public void OrderedEventTest()
        {
            // Arrange
            OrderedEvent evt = new OrderedEvent();
            int          q1 = 100, q2 = 200;

            firstCalled = secondCalled = -1;

            evt.Bind(this.FirstCall, q1);

            evt.Bind(this.SecondCall, q2);

            // Act
            evt.Invoke();

            // Assert
            Assert.AreEqual(1, firstCalled);
            Assert.AreEqual(2, secondCalled);

            // Test unbind
            firstCalled = secondCalled = -1;

            // Act
            evt.Unbind(SecondCall);
            evt.Invoke();

            // Assert
            Assert.AreEqual(1, firstCalled);
            Assert.AreEqual(-1, secondCalled);
        }
예제 #2
0
    public void BlendInvoke(OrderedEvent other)
    {
        if (other == null)
        {
            Invoke();
            return;
        }

        int i = delegates.Count - 1, j = other.delegates.Count - 1;

        //Work through the lists until one of them is done
        while (i >= 0 && j >= 0)
        {
            if (priorities[i] < other.priorities[j])
            {
                delegates[i]();
                i--;
            }
            else
            {
                other.delegates[j]();
                j--;
            }
        }

        //Clear out rest of our list, if it exists
        for (; i >= 0; i--)
        {
            delegates[i]();
        }

        //Clear out their list, if it exists
        for (; j >= 0; j--)
        {
            other.delegates[j]();
        }
    }
예제 #3
0
        protected override void EndBatchComplete()
        {
            if (_pendingWork)
            {
                return;
            }
            try
            {
                if (_needToAbort)
                {
                    Transaction.Rollback();

                    CommitConfirm.DTCCommitConfirm(ComTxn, false);
                }
                else
                {
                    Transaction.Commit();

                    CommitConfirm.DTCCommitConfirm(ComTxn, true);
                }
            }
            catch
            {
                try
                {
                    CommitConfirm.DTCCommitConfirm(ComTxn, false);
                }
                catch
                {
                }
            }
            //  note the pending work check at the top of this function removes the need to check a needToLeave flag
            Control.Leave();

            OrderedEvent?.Set();
        }