CSharpTest.Net
OnError Event
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Threading Namespace > WaitAndContinueWorker Class : OnError Event

Glossary Item Box

Raised when an uncaught exception is thrown while processing the work queue

Syntax

Visual Basic (Declaration) 
Public Event OnError As ErrorEventHandler
C# 
public event ErrorEventHandler OnError

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