CSharpTest.Net
Dispose Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.IO Namespace > FragmentedFile Class : Dispose Method

Glossary Item Box

Closes the storage, a must-do to save a costly recomputation of free block on open

Syntax

Visual Basic (Declaration) 
Public Sub Dispose() 
C# 
public void Dispose()

Exceptions

ExceptionDescription
System.IO.InvalidDataException 

Example

Library/Library.Test/TestFragmentedFile.cs

C#Copy Code
SharedMemoryStream shared = new SharedMemoryStream();
FragmentedFile.CreateNew(shared, 512, 100, 2).Dispose();

using (FragmentedFile ff = new FragmentedFile(shared, 512, 100, 2))
{
    long id;
    byte[] bytes = MakeBytes(255);
    using (Stream write = ff.Create(out id))
    using (ITransactable trans = (ITransactable)write)
    {
        write.Write(bytes, 0, bytes.Length);
        trans.Commit();
        Assert.AreEqual(bytes, IOStream.ReadAllBytes(ff.Open(id, FileAccess.Read)));
        trans.Rollback();
    }

    AssertThrows<InvalidDataException>(delegate() { ff.Open(id, FileAccess.Read); });
}
VB.NETCopy Code
Dim [shared] As New SharedMemoryStream()
FragmentedFile.CreateNew([shared], 512, 100, 2).Dispose()

Using ff As New FragmentedFile([shared], 512, 100, 2)
    Dim id As Long
    Dim bytes As Byte() = MakeBytes(255)
    Using write As Stream = ff.Create(id)
        Using trans As ITransactable = DirectCast(write, ITransactable)
            write.Write(bytes, 0, bytes.Length)
            trans.Commit()
            Assert.AreEqual(bytes, IOStream.ReadAllBytes(ff.Open(id, FileAccess.Read)))
            trans.Rollback()
        End Using
    End Using

    AssertThrows(Of InvalidDataException)(Function() Do
        ff.Open(id, FileAccess.Read)
    End Function)
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