Enqueues a flush command and returns immediately
Syntax
Visual Basic (Declaration) | |
---|
Public Sub BeginFlush() |
C# | |
---|
public void BeginFlush() |
Example
Library/Library.Test/TestBackgroundWriter.cs
C# | Copy Code |
---|
using (ManualResetEvent mre = new ManualResetEvent(false))
using (TempFile temp = new TempFile())
using (TestStream io = new TestStream(temp.Open()))
using (BackgroundWriter wtr = new BackgroundWriter(io))
{
const int sz = 1000;
const int iter = 10000;
var bytes = new byte[sz];
for (int i = 0; i < iter; i++)
wtr.Write(bytes, 0, sz);
wtr.BeginFlush();
Assert.IsFalse(io.Flushed);
wtr.Perform(s => mre.Set());
Assert.IsTrue(mre.WaitOne(60000, false));
Assert.IsTrue(io.Flushed);
Assert.AreEqual(sz * iter, io.Position);
Assert.AreEqual(sz * iter, io.Length);
} |
VB.NET | Copy Code |
---|
Using mre As New ManualResetEvent(False)
Using temp As New TempFile()
Using io As New TestStream(temp.Open())
Using wtr As New BackgroundWriter(io)
Const sz As Integer = 1000
Const iter As Integer = 10000
Dim bytes As var = New Byte(sz) {}
Dim i As Integer = 0
While i < iter
wtr.Write(bytes, 0, sz)
System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
End While
wtr.BeginFlush()
Assert.IsFalse(io.Flushed)
wtr.Perform(Function(s) mre.[Set]())
Assert.IsTrue(mre.WaitOne(60000, False))
Assert.IsTrue(io.Flushed)
Assert.AreEqual(sz * iter, io.Position)
Assert.AreEqual(sz * iter, io.Length)
End Using
End Using
End Using
End Using |
Requirements
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7
See Also