ReferenceCountedObject.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / TransactionBridge / Microsoft / Transactions / Wsat / Messaging / ReferenceCountedObject.cs / 1 / ReferenceCountedObject.cs

                            //------------------------------------------------------------------------------ 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//-----------------------------------------------------------------------------
using System;
using System.Threading; 
using DiagnosticUtility = Microsoft.Transactions.Bridge.DiagnosticUtility;
 
namespace Microsoft.Transactions.Wsat.Messaging 
{
    abstract class ReferenceCountedObject 
    {
        int refCount = 1;

        public void AddRef() 
        {
            int refs = Interlocked.Increment(ref this.refCount); 
            if (refs <= 0) 
            {
                // Reference counting bug was detected. 
                // This means that the code is buggy and needs to be fixed.
                DiagnosticUtility.FailFast("Reference count below 0");
            }
        } 

        public void Release() 
        { 
            int refs = Interlocked.Decrement(ref this.refCount);
            if (refs < 0) 
            {
                // Reference counting bug was detected.
                // This means that the code is buggy and needs to be fixed.
                DiagnosticUtility.FailFast("Reference count below 0"); 
            }
 
            if (refs == 0) 
                Close();
        } 

        protected abstract void Close();
    }
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK