CSharpTest.Net
ForcedEventHandlerForControl<TEventArgs> Constructor(Control,EventHandler<TEventArgs>)
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Delegates Namespace > ForcedEventHandlerForControl<TEventArgs> Class > ForcedEventHandlerForControl<TEventArgs> Constructor : ForcedEventHandlerForControl<TEventArgs> Constructor(Control,EventHandler<TEventArgs>)

control
handler

Glossary Item Box

Constructs an EventHandler for the specified method on the given control instance.

Syntax

Visual Basic (Declaration) 
Public Function New( _
   ByVal control As Control, _
   ByVal handler As EventHandler(Of TEventArgs) _
)
C# 
public ForcedEventHandlerForControl<TEventArgs>( 
   Control control,
   EventHandler<TEventArgs> handler
)

Parameters

control
handler

Example

Library/Library.Test/TestDelegates.cs

C#Copy Code
ForcedEventHandlerForControl<VerifiedReceiptEventArgs> handler;
handler = new ForcedEventHandlerForControl<VerifiedReceiptEventArgs>(_form, VerifiedReceipt);
handler = new ForcedEventHandlerForControl<VerifiedReceiptEventArgs>(_form, new VerifiedReceiptEventHandler(handler.EventHandler));
VerifiedReceiptEventArgs args = new VerifiedReceiptEventArgs();
_form.Shown += delegate(object s, EventArgs e) { System.Threading.Thread.Sleep(100); _form.Close(); };
_thread.Start();
int total = 0, countOnThread = 0, countOffThread = 0;
try
{
    for (total = 1; total < 1000000; total++)
    {
        handler.EventHandler(null, args.Reset());
        Assert.IsTrue(args.Received);
        if (args.OnThread)
            countOnThread++;
        else
            countOffThread++;
        //Assert.IsTrue(args.OnThread);
        //Console.Error.WriteLine("Threaded = {0}", args.OnThread);
        if (_form.IsDisposed)
            break;
    }
    Assert.AreEqual(total, countOnThread + countOffThread);
    Assert.IsTrue(_form.IsDisposed);
    Assert.AreNotEqual(0, countOnThread);
    Assert.AreNotEqual(0, countOffThread);
}
catch (Exception e)
{
    Console.Error.WriteLine(e.ToString());
    throw;
}
finally
{
    _thread.Join();
}
VB.NETCopy Code
Dim handler As ForcedEventHandlerForControl(Of VerifiedReceiptEventArgs)
handler = New ForcedEventHandlerForControl(Of VerifiedReceiptEventArgs)(_form, VerifiedReceipt)
handler = New ForcedEventHandlerForControl(Of VerifiedReceiptEventArgs)(_form, New VerifiedReceiptEventHandler(handler.EventHandler))
Dim args As New VerifiedReceiptEventArgs()
_form.Shown += Function(s As Object, e As EventArgs) Do
    System.Threading.Thread.Sleep(100)
    _form.Close()
End Function
_thread.Start()
Dim total As Integer = 0, countOnThread As Integer = 0, countOffThread As Integer = 0
Try
    total = 1
    While total < 1000000
        handler.EventHandler(Nothing, args.Reset())
        Assert.IsTrue(args.Received)
        If args.OnThread Then
            System.Math.Max(System.Threading.Interlocked.Increment(countOnThread),countOnThread - 1)
        Else
            System.Math.Max(System.Threading.Interlocked.Increment(countOffThread),countOffThread - 1)
        End If
        'Assert.IsTrue(args.OnThread);
        'Console.Error.WriteLine("Threaded = {0}", args.OnThread);
        If _form.IsDisposed Then
            Exit While
        End If
        System.Math.Max(System.Threading.Interlocked.Increment(total),total - 1)
    End While
    Assert.AreEqual(total, countOnThread + countOffThread)
    Assert.IsTrue(_form.IsDisposed)
    Assert.AreNotEqual(0, countOnThread)
    Assert.AreNotEqual(0, countOffThread)
Catch e As Exception
    Console.[Error].WriteLine(e.ToString())
    Throw
Finally
    _thread.Join()
End Try

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys