Given the following method :
public static void ExecuteAsync( this EventHandler eH, object sender, EventArgs eA ) {
eH.GetInvocationList( ).Cast<EventHandler>( ).ToList( ).ForEach( e => {
e.BeginInvoke( sender, eA, IAR =>
( ( IAR as AsyncResult ).AsyncDelegate as EventHandler ).EndInvoke( IAR ), null );
} );
}
I noticed that e
has a property Target.
When I was looking further into it I discovered I can check if e.Target is System.Windows.Controls.Control
or e.Target is System.Windows.Forms.Control
.
This is awesome because in the case of using this extension, as a matter of convenience (and me being lazy), I want to be able to tell if the delegate target needs to invoke the delegate or not (In the case of WinForms : Control.Invoke( foo )
; In the case of WPF : Control.Dispatcher.Invoke( foo )
).
I don't need to know how to cast the object to what it's actual type is (I can live without that) : I just need to know if how I can cast the object such that I can access the InvokeRequired
property and Invoke
methods (in the case of a WinForms control), or the Dispatcher
property (For access to the Dispatcher.CheckAccess( )
function and Dispatcher.Invoke( )
method).
Is this possible? How can I go about doing this? (I've tried casting e.Target to System.Windows.Control.Control
but the result does not have a Dispatcher
property).
EDIT
As per the request for the casting code (and imports/references) :
To determine if it is a WPF control :
( if e.Target is System.Windows.Controls.Control ){ //Fully Qualified
( e.Target as System.Windows.Controls.Control)./*...*/;
}
To determine if it is a WinForms control :
( if e.Target is System.Windows.Forms.Control ){ //Fully Qualified
( e.Target as System.Windows.Forms.Control )./*...*/;
}
The project makes reference to several libraries :
Microsoft.CSharp
MySql.Data
PresentationFramework
System
System.Configuration
System.Configuration.Install
System.Core
System.Data
System.Data.DataSetExtensions
System.Drawing
System.Management
System.Windows.Forms
System.Xml
System.Xml.Linq