T
CSharpTest.Net
DebugLockFactory<T> Class
Members  Example  See Also  Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Synchronization Namespace : DebugLockFactory<T> Class

Glossary Item Box

Creates a debugging lock factory that can track locks allocated and all acquired/released read/write locks

Syntax

Visual Basic (Declaration) 
Public Class DebugLockFactory(Of T As {New, ILockStrategy}) 
   Inherits DebugLockFactory
   Implements CSharpTest.Net.Interfaces.IFactory(Of ILockStrategy)ILockFactory 
C# 
public class DebugLockFactory<T> : DebugLockFactory, CSharpTest.Net.Interfaces.IFactory<ILockStrategy>ILockFactory  
where T: new(), ILockStrategy

Type Parameters

T

Example

Library/Library.Test/LockingTests/TestDebugLocking.cs

C#Copy Code
DebugLockFactory<SimpleReadWriteLocking> factory = new DebugLockFactory<SimpleReadWriteLocking>(
    false, 0, 1, false, 1);

using (ILockStrategy lck = factory.Create())
{
    using (lck.Write())
    using (lck.Write()) //second lock, allow recurse 1 time as per constructor
    {
        try { using (lck.Write()) { Assert.Fail(); } }
        catch (Exception ex)
        {
            Assert.IsTrue(ex is DebugAssertionFailedException);//nesting prohibited by debug lock
        }
    }

    using (lck.Read())
    using (lck.Read()) //second lock, allow recurse 1 time as per constructor
    {
        try { using (lck.Read()) { Assert.Fail(); } }
        catch (Exception ex)
        {
            Assert.IsTrue(ex is DebugAssertionFailedException);//nesting prohibited by debug lock
        }
    }
}
VB.NETCopy Code
Dim factory As New DebugLockFactory(Of SimpleReadWriteLocking)(False, 0, 1, False, 1)

Using lck As ILockStrategy = factory.Create()
    Using lck.Write()
        Using lck.Write()
            'second lock, allow recurse 1 time as per constructor
            Try
                Using lck.Write()
                    Assert.Fail()
                End Using
            Catch ex As Exception
                    'nesting prohibited by debug lock
                Assert.IsTrue(TypeOf ex Is DebugAssertionFailedException)
            End Try
        End Using
    End Using

    Using lck.Read()
        Using lck.Read()
            'second lock, allow recurse 1 time as per constructor
            Try
                Using lck.Read()
                    Assert.Fail()
                End Using
            Catch ex As Exception
                    'nesting prohibited by debug lock
                Assert.IsTrue(TypeOf ex Is DebugAssertionFailedException)
            End Try
        End Using
    End Using
End Using

Inheritance Hierarchy

System.Object
   CSharpTest.Net.Synchronization.LockCounterFactory
      CSharpTest.Net.Synchronization.DebugLockFactory
         CSharpTest.Net.Synchronization.DebugLockFactory<T>

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys