Closes all streams and clears all in-memory data.
            
            
            
Syntax
| Visual Basic (Declaration) |   | 
|---|
Public Sub Dispose()   | 
 
            
            
             
            
						
            
            
            
            
Example
Library/Library.Test/TestTransactedCompoundFile.cs
             | C# |  Copy Code | 
|---|
using (TempFile temp = new TempFile())
{
    var options = new TransactedCompoundFile.Options(temp.TempPath) { BlockSize = 512 };
    const int count = 4;
    byte[] sample = new byte[options.MaxWriteSize / 3];
    new Random().NextBytes(sample);
    using (TransactedCompoundFile file = new TransactedCompoundFile(options))
    {
        for (uint h = 1u; h < count; h++)
            Assert.AreEqual(h, file.Create());
        for (uint h = 1u; h < count; h++)
            file.Write(h, sample, 0, sample.Length);
        file.Commit();
    }
    //Corrupts the primary of the first block, and secondary of the last block:
    using (Stream f = temp.Open())
    {
        f.Write(sample, 0, 100);
        f.Seek(-100, SeekOrigin.End);
        f.Write(sample, 0, 100);
    }
    try
    {
        options.LoadingRule = TransactedCompoundFile.LoadingRule.Primary;
        new TransactedCompoundFile(options).Dispose();
        Assert.Fail("Should not load");
    }
    catch (InvalidDataException)
    {
    }
    try
    {
        options.LoadingRule = TransactedCompoundFile.LoadingRule.Secondary;
        new TransactedCompoundFile(options).Dispose();
        Assert.Fail("Should not load");
    }
    catch (InvalidDataException)
    {
    }
    options.LoadingRule = TransactedCompoundFile.LoadingRule.Default;
    using (TransactedCompoundFile file = new TransactedCompoundFile(options))
    {
        for (uint h = 1u; h < count; h++)
            CompareBytes(sample, 0, sample.Length, IOStream.ReadAllBytes(file.Read(h)));
        //Commit fixes corruption
        file.Commit();
    }
    options.LoadingRule = TransactedCompoundFile.LoadingRule.Primary;
    new TransactedCompoundFile(options).Dispose();
    options.LoadingRule = TransactedCompoundFile.LoadingRule.Secondary;
    new TransactedCompoundFile(options).Dispose();
} | 
 
| VB.NET |  Copy Code | 
|---|
Using temp As New TempFile()
    Dim options As var = New TransactedCompoundFile.Options(temp.TempPath) With { _
        Key .BlockSize = 512 _
    }
    Const  count As Integer = 4
    Dim sample As Byte() = New Byte(options.MaxWriteSize / 3) {}
    New Random().NextBytes(sample)
    Using file As New TransactedCompoundFile(options)
        Dim h As UInteger = 1UI
        While h < count
            Assert.AreEqual(h, file.Create())
            System.Math.Max(System.Threading.Interlocked.Increment(h),h - 1)
        End While
        Dim h As UInteger = 1UI
        While h < count
            file.Write(h, sample, 0, sample.Length)
            System.Math.Max(System.Threading.Interlocked.Increment(h),h - 1)
        End While
        file.Commit()
    End Using
    'Corrupts the primary of the first block, and secondary of the last block:
    Using f As Stream = temp.Open()
        f.Write(sample, 0, 100)
        f.Seek(-100, SeekOrigin.[End])
        f.Write(sample, 0, 100)
    End Using
    Try
        options.LoadingRule = TransactedCompoundFile.LoadingRule.Primary
        New TransactedCompoundFile(options).Dispose()
        Assert.Fail("Should not load")
    Catch generatedExceptionName As InvalidDataException
    End Try
    Try
        options.LoadingRule = TransactedCompoundFile.LoadingRule.Secondary
        New TransactedCompoundFile(options).Dispose()
        Assert.Fail("Should not load")
    Catch generatedExceptionName As InvalidDataException
    End Try
    options.LoadingRule = TransactedCompoundFile.LoadingRule.[Default]
    Using file As New TransactedCompoundFile(options)
        Dim h As UInteger = 1UI
        While h < count
            CompareBytes(sample, 0, sample.Length, IOStream.ReadAllBytes(file.Read(h)))
            System.Math.Max(System.Threading.Interlocked.Increment(h),h - 1)
        End While
        'Commit fixes corruption
        file.Commit()
    End Using
    options.LoadingRule = TransactedCompoundFile.LoadingRule.Primary
    New TransactedCompoundFile(options).Dispose()
    options.LoadingRule = TransactedCompoundFile.LoadingRule.Secondary
    New TransactedCompoundFile(options).Dispose()
End Using | 
 
 
            
            
Requirements
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7
 
            
            
See Also