rt.

解决方案 »

  1.   

    http://blog.csdn.net/alpsboy/archive/2006/06/30/856597.aspx
      

  2.   

    大家看看这个行不行? 貌似就是的.public static class InvocationHelper<T>
    {
    public static void Invoke(T eventHandler)
    {
    InvocationHelper<T>.Invoke(eventHandler, null);
    }
    public static void Invoke(T eventHandler, params object[] arguments)
    {
    // Check that T is a delegate type
    if (!(eventHandler is Delegate))
    {
    throw new ArgumentException(string.Format("Type {0} is not derived from {1}", eventHandler.GetType().Name, typeof(Delegate).Name));
    }
    // Cast the to a delegate now since it's needed later
    Delegate handler = (eventHandler as Delegate);
    int requiredParameters = handler.Method.GetParameters().Length;
    // Check that the correct number of arguments have been supplied
    if (requiredParameters != arguments.Length)
    {
    throw new ArgumentException(string.Format("{0} arguments provided when {1} {2} required.", arguments.Length, requiredParameters, ((requiredParameters == 1) ? "is" : "are")));
    }
    // Get a local copy of the invocation list in case it changes
    Delegate[] invocationList = handler.GetInvocationList();
    // Check that it's not null
    if (invocationList == null)
    {
    return;
    }
    // Loop through delegates and check for ISynchronizeInvoke
    foreach (Delegate singleCastDelegate in invocationList)
    {
    ISynchronizeInvoke synchronizeTarget = singleCastDelegate.Target as ISynchronizeInvoke;
    // Check to see if the interface was supported
    if (synchronizeTarget == null)
    {
    // Invoke delegate normally
    singleCastDelegate.DynamicInvoke(arguments);
    }
    else
    {
    // Invoke through synchronization interface
    synchronizeTarget.BeginInvoke(singleCastDelegate, arguments);
    }
    }
    }
    }