CSharpTest.Net
AddWork(IWaitAndContinue) Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Threading Namespace > WaitAndContinueWorker Class > AddWork Method : AddWork(IWaitAndContinue) Method

item

Glossary Item Box

Adds a unit of work to the list

Syntax

Visual Basic (Declaration) 
Public Overloads Sub AddWork( _
   ByVal item As IWaitAndContinue _
) 
C# 
public void AddWork( 
   IWaitAndContinue item
)

Parameters

item

Exceptions

ExceptionDescription
System.ObjectDisposedExceptionThe exception that is thrown when an operation is performed on a disposed object.

Example

Library/Library.Test/TestWaitAndContinue.cs

C#Copy Code
using (WaitAndContinueWorker work = new WaitAndContinueWorker())
{
    SampleWork item = new SampleWork();
    item.WorkThrows = true;
    work.AddWork(item);

    ManualResetEvent mreError = new ManualResetEvent(false);
    Exception error = null;
    work.OnError += delegate(object o, ErrorEventArgs e) { error = e.GetException(); mreError.Set(); };

    item.Ready.Set();
    Assert.IsTrue(mreError.WaitOne(1000, false));
    Assert.IsTrue(error is ArgumentOutOfRangeException);
    Assert.IsTrue(((ArgumentOutOfRangeException)error).ParamName == "WorkThrows");
}
VB.NETCopy Code
Using work As New WaitAndContinueWorker()
    Dim item As New SampleWork()
    item.WorkThrows = True
    work.AddWork(item)

    Dim mreError As New ManualResetEvent(False)
    Dim [error] As Exception = Nothing
    work.OnError += Function(o As Object, e As ErrorEventArgs) Do
        [error] = e.GetException()
        mreError.[Set]()
    End Function

    item.Ready.[Set]()
    Assert.IsTrue(mreError.WaitOne(1000, False))
    Assert.IsTrue(TypeOf [error] Is ArgumentOutOfRangeException)
    Assert.IsTrue((DirectCast([error], ArgumentOutOfRangeException)).ParamName = "WorkThrows")
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