CSharpTest.Net
DebugLockFactory<T> Constructor(Boolean,Int32,Int32,Boolean,Int32)
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Synchronization Namespace > DebugLockFactory<T> Class > DebugLockFactory<T> Constructor : DebugLockFactory<T> Constructor(Boolean,Int32,Int32,Boolean,Int32)

captureStack
limitTimeout
limitNestedReaders
concurrentReads
limitNestedWriters

Glossary Item Box

Constructs the lock tracking factory

Syntax

Visual Basic (Declaration) 
Public Function New( _
   ByVal captureStack As Boolean, _
   ByVal limitTimeout As Integer, _
   ByVal limitNestedReaders As Integer, _
   ByVal concurrentReads As Boolean, _
   ByVal limitNestedWriters As Integer _
)
C# 
public DebugLockFactory<T>( 
   bool captureStack,
   int limitTimeout,
   int limitNestedReaders,
   bool concurrentReads,
   int limitNestedWriters
)

Parameters

captureStack
limitTimeout
limitNestedReaders
concurrentReads
limitNestedWriters

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

Requirements

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

See Also

Generated with Document! X 2011 by Innovasys