本文整理汇总了C#中System.MulticastDelegate.GetInvocationList方法的典型用法代码示例。如果您正苦于以下问题:C# MulticastDelegate.GetInvocationList方法的具体用法?C# MulticastDelegate.GetInvocationList怎么用?C# MulticastDelegate.GetInvocationList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.MulticastDelegate
的用法示例。
在下文中一共展示了MulticastDelegate.GetInvocationList方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InvokeDelegates
public static void InvokeDelegates(MulticastDelegate mDelegate, object sender, EventArgs e)
{
if (mDelegate == null)
return;
Delegate[] delegates = mDelegate.GetInvocationList();
if (delegates == null)
return;
// Invoke delegates within their threads
foreach (Delegate _delegate in delegates)
{
if (_delegate.Target.GetType().ContainsGenericParameters)
{
Console.WriteLine("Cannot invoke event handler on a generic type.");
return;
}
object[] contextAndArgs = { sender, e };
ISynchronizeInvoke syncInvoke = _delegate.Target as ISynchronizeInvoke;
{
if (syncInvoke != null)
{
// This case applies to the situation when Delegate.Target is a
// Control with an open window handle.
syncInvoke.Invoke(_delegate, contextAndArgs);
}
else
{
_delegate.DynamicInvoke(contextAndArgs);
}
}
}
}
示例2: InvokeHandler
private void InvokeHandler( MulticastDelegate handlerList, EventArgs e )
{
object[] args = new object[] { this, e };
foreach( Delegate handler in handlerList.GetInvocationList() )
{
object target = handler.Target;
System.Windows.Forms.Control control
= target as System.Windows.Forms.Control;
try
{
if ( control != null && control.InvokeRequired )
//control.Invoke( handler, args );
control.BeginInvoke(handler, args);
else
handler.Method.Invoke( target, args );
}
catch( Exception ex )
{
// TODO: Stop rethrowing this since it goes back to the
// Test domain which may not know how to handle it!!!
Console.WriteLine( "Exception:" );
Console.WriteLine( ex );
//throw new TestEventInvocationException( ex );
//throw;
}
}
}
示例3: FireEventToDelegates
internal void FireEventToDelegates(MulticastDelegate md, ManagementEventArgs args)
{
try
{
if (md != null)
{
Delegate[] invocationList = md.GetInvocationList();
for (int i = 0; i < (int)invocationList.Length; i++)
{
Delegate @delegate = invocationList[i];
try
{
object[] objArray = new object[2];
objArray[0] = this.sender;
objArray[1] = args;
@delegate.DynamicInvoke(objArray);
}
catch
{
}
}
}
}
catch
{
}
}
示例4: DisplayMulticastInfo
static void DisplayMulticastInfo(MulticastDelegate md)
{
foreach(var d in md.GetInvocationList())
{
DisplayDelegateInfo(d);
}
}
示例5: SafeMultiInvoke
public static object[] SafeMultiInvoke(MulticastDelegate delegateToFire, params object[] parameters )
{
Delegate[] invocationList = delegateToFire.GetInvocationList();
object[] retvals = new object[invocationList.Length];
int i=0;
foreach (Delegate dlg in invocationList)
{
retvals[i++] = SafeInvoke(dlg, parameters);
}
return retvals;
}
示例6: FireEventToDelegates
internal void FireEventToDelegates(MulticastDelegate md, ManagementEventArgs args)
{
try
{
if (md != null)
{
foreach (Delegate delegate2 in md.GetInvocationList())
{
try
{
delegate2.DynamicInvoke(new object[] { this.sender, args });
}
catch
{
}
}
}
}
catch
{
}
}
示例7: InvokeMulticast
public static void InvokeMulticast(object sender, MulticastDelegate md, EventArgs e)
{
if (md == null)
return;
foreach (StdMulticastDelegation Caster in md.GetInvocationList())
{
ISynchronizeInvoke SyncInvoke = Caster.Target as ISynchronizeInvoke;
try
{
if (SyncInvoke != null && SyncInvoke.InvokeRequired)
SyncInvoke.Invoke(Caster, new object[] { sender, e });
else
Caster(sender, e);
}
catch (System.Exception ex)
{
Console.WriteLine("Event handling failed. \n");
Console.WriteLine("{0}:\n", ex.ToString());
}
}
}
示例8: ContainsDelegate
internal static bool ContainsDelegate(MulticastDelegate source, Delegate d)
{
if (null != source && null != d)
{
Delegate[] list = source.GetInvocationList();
if (null != list)
{
for (int i = 0; i < list.Length; i++)
{
if (list[i].Equals(d))
return true;
}
}
}
return false;
}
示例9: FindBuilder
internal static Delegate FindBuilder(MulticastDelegate mcd)
{
if (mcd != null)
{
Delegate[] invocationList = mcd.GetInvocationList();
for (int i = 0; i < invocationList.Length; i++)
{
if (invocationList[i].Target is DbCommandBuilder)
{
return invocationList[i];
}
}
}
return null;
}
示例10: GetDelegatesWithNonTransientTargets
internal Delegate[] GetDelegatesWithNonTransientTargets(MulticastDelegate mDelegate)
{
return mDelegate.GetInvocationList().Where(x => x.Target == null || !CheckTransient(x.Target)).ToArray();
}
示例11: FireEventToDelegates
/// <summary>
/// Custom handler for firing a WMI event to a list of delegates. We use
/// the process thread pool to handle the firing.
/// </summary>
/// <param name="md">The MulticastDelegate representing the collection
/// of targets for the event</param>
/// <param name="args">The accompanying event arguments</param>
internal void FireEventToDelegates (MulticastDelegate md, ManagementEventArgs args)
{
try
{
if (null != md)
{
#if USEPOOL
Delegate[] delegateList = md.GetInvocationList ();
if (null != delegateList)
{
int numDelegates = delegateList.Length;
AutoResetEvent[] waitHandles = new AutoResetEvent [numDelegates];
/*
* For each target delegate, queue a request to the
* thread pool to handle the POST. We pass as state the
* 1) Target delegate
* 2) Event args
* 3) AutoResetEvent that the thread should signal to
* indicate that it is done.
*/
for (int i = 0; i < numDelegates; i++)
{
waitHandles [i] = new AutoResetEvent (false);
ThreadPool.QueueUserWorkItem (
new WaitCallback (this.FireEventToDelegate),
new WmiEventState (delegateList[i], args, waitHandles[i]));
}
/*
* We wait for all the delegates to signal that they are done.
* This is because if we return from the IWbemObjectSink callback
* before they are all done, it is possible that a delegate will
* begin to process the next callback before the current callback
* processing is done.
*/
WaitHandle.WaitAll (waitHandles, 10000, true);
}
}
#endif
foreach (Delegate d in md.GetInvocationList())
{
try
{
d.DynamicInvoke (new object [] {this.sender, args});
}
catch
{
}
}
}
}