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

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 Delegate _
)
C# 
public EventHandlerForActiveControl<TEventArgs>( 
   Control control,
   Delegate handler
)

Parameters

control
handler

Example

Library/Library.Test/TestDelegates.cs

C#Copy Code
EventHandlerForActiveControl<VerifiedReceiptEventArgs> handler;
handler = new EventHandlerForActiveControl<VerifiedReceiptEventArgs>(_form, VerifiedReceipt);
handler = new EventHandlerForActiveControl<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());
        if (args.OnThread)
        {
            Assert.IsTrue(args.Received);
            countOnThread++;
        }
        else
        {
            Assert.IsFalse(args.Received);
            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 EventHandlerForActiveControl(Of VerifiedReceiptEventArgs)
handler = New EventHandlerForActiveControl(Of VerifiedReceiptEventArgs)(_form, VerifiedReceipt)
handler = New EventHandlerForActiveControl(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())
        If args.OnThread Then
            Assert.IsTrue(args.Received)
            System.Math.Max(System.Threading.Interlocked.Increment(countOnThread),countOnThread - 1)
        Else
            Assert.IsFalse(args.Received)
            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