本文整理汇总了C#中System.MulticastDelegate类的典型用法代码示例。如果您正苦于以下问题:C# MulticastDelegate类的具体用法?C# MulticastDelegate怎么用?C# MulticastDelegate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MulticastDelegate类属于System命名空间,在下文中一共展示了MulticastDelegate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EventUnhooked
public void EventUnhooked(MulticastDelegate eventHandler)
{
// The rest of the method must be inline or the stack trace won't be correct.
StackTrace currentStackTrace = new StackTrace();
// Make sure we were called from a "remove" method of an event.
string callingEventMethodName = currentStackTrace.GetFrame(1).GetMethod().Name;
Debug.Assert(callingEventMethodName.StartsWith("remove_", StringComparison.OrdinalIgnoreCase), "EventUnhooked called from an invalid method");
string eventName = callingEventMethodName.Substring("remove_".Length);
if (eventHandler == null)
{
// If the MulticastDelegate is null, then the event is completely unhooked.
_eventsHooked.Remove(eventName);
_eventsUnhooked.Remove(eventName);
}
else
{
// Save the current stack trace for debugging.
if (!_eventsUnhooked.ContainsKey(eventName))
_eventsUnhooked[eventName] = new List<StackTrace>();
_eventsUnhooked[eventName].Add(currentStackTrace);
}
}
示例2: DisplayMulticastInfo
static void DisplayMulticastInfo(MulticastDelegate md)
{
foreach(var d in md.GetInvocationList())
{
DisplayDelegateInfo(d);
}
}
示例3: InvokeMulticast
public static void InvokeMulticast(object sender, MulticastDelegate md)
{
if (md != null)
{
InvokeMulticast(sender, md, null);
}
}
示例4: 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;
}
}
}
示例5: 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
{
}
}
示例6: CallEvent
static public void CallEvent(string objMgPath, string eventName, MulticastDelegate delgt, params object[] eventParams)
{
try
{
delgt.DynamicInvoke(eventParams);
if (!PurviewMgr.IsMainHost)
{
object[] newparams = new object[eventParams.Length];
for (int i = 0; i < eventParams.Length; i++)
{
if (eventParams[i] is IGameObj)
{
newparams[i] = new GameObjSyncInfo(((IGameObj)eventParams[i]).MgPath);
}
else
{
newparams[i] = eventParams[i];
}
}
// 通过网络协议传递给主机
SyncCasheWriter.SubmitNewEvent(objMgPath, eventName, newparams);
}
}
catch (Exception ex)
{
Log.Write(ex.ToString());
}
}
示例7: Remove
/// <summary>
/// Remove the given delegate from my invocation list.
/// </summary>
protected override sealed Delegate Remove(Delegate other)
{
if (this.Equals(other))
{
// Front of the list
var result = next;
next = null;
return result;
}
MulticastDelegate parent = this;
while ((parent != null) && (!other.Equals(parent.next)))
{
parent = parent.next;
}
if (parent != null)
{
MulticastDelegate otherx = parent.next;
parent.next = otherx.next;
otherx.next = null;
}
return this;
}
示例8: 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);
}
}
}
}
示例9: DelegateFactory
/// <summary>
/// Initializes the class with the given <paramref name="targetDelegate"/>
/// </summary>
/// <param name="targetDelegate">The delegate that will be used to instantiate the factory.</param>
public DelegateFactory(MulticastDelegate targetDelegate)
{
if (targetDelegate.Method.ReturnType == typeof(void))
throw new ArgumentException("The factory delegate must have a return type.");
_targetDelegate = targetDelegate;
}
示例10: BuildFor
public static string BuildFor(MulticastDelegate action, string prefixToExclude)
{
var name = action.Method.Name;
if (name.StartsWith(prefixToExclude, true, CultureInfo.CurrentCulture))
{
name = name.Substring(prefixToExclude.Length).TrimStart('_');
}
return BuildFor(name);
}
示例11: quadl
/// <summary>Find integral using Lobatto Rule</summary>
/// <param name="f">Function to integrate. Must be of the
/// form y = f(x) where x and y are of type "double".</param>
/// <param name="a">Lower bound of integral</param>
/// <param name="b">Upper bound of integral</param>
/// <returns>Area under funciton curve with an error of +- 1e-6</returns>
///
/// <remarks>
/// Derived from "W. Gander and W. Gautschi: Adaptive Quadrature -
/// Revisited, BIT Vol. 40, No. 1, March 2000, pp. 84--101. CS technical
/// report: Report (gzipped, 82K). Programs: adaptsim.m, adaptlob.m", which
/// can be found at: http://www.inf.ethz.ch/personal/gander/.
///
/// The defualt error of 1e-6 was chosen in order to give results
/// comparible in speed and precision to Matlab R2009a.
/// </remarks>
public static double quadl(MulticastDelegate f, double a, double b)
{
double tol = 1e-6; // to have the same level of precision as Matlab
// in the future, this could be an input?
double m = (a + b) / 2.0;
double h = (b - a) / 2.0;
double alpha = Math.Sqrt(2.0 / 3.0);
double beta = 1.0 / Math.Sqrt(5.0);
double c1 = 0.942882415695480;
double c2 = 0.641853342345781;
double c3 = 0.236383199662150;
double y1 = (double)f.DynamicInvoke(a),
y2 = (double)f.DynamicInvoke(m - c1 * h),
y3 = (double)f.DynamicInvoke(m - alpha * h),
y4 = (double)f.DynamicInvoke(m - c2 * h),
y5 = (double)f.DynamicInvoke(m - beta * h),
y6 = (double)f.DynamicInvoke(m - c3 * h),
y7 = (double)f.DynamicInvoke(m),
y8 = (double)f.DynamicInvoke(m + c3 * h),
y9 = (double)f.DynamicInvoke(m + beta * h),
y10= (double)f.DynamicInvoke(m + c2 * h),
y11= (double)f.DynamicInvoke(m + alpha * h),
y12= (double)f.DynamicInvoke(m + c1 * h),
y13= (double)f.DynamicInvoke(b);
double fa = y1;
double fb = y13;
double i2 = (h / 6.0) * (y1 + y13 + 5 * (y5 + y9));
double i1 = (h / 1470.0) * (77 * (y1 + y13) + 432 * (y3 + y11) + 625 * (y5 + y9) + 672 * y7);
double i0 = h * (
0.0158271919734802 * (y1 + y13) +
0.0942738402188500 * (y2 + y12) +
0.155071987336585 * (y3 + y11) +
0.188821573960182 * (y4 + y10) +
0.199773405226859 * (y5 + y9) +
0.224926465333340 * (y6 + y8) +
0.242611071901408 * y7);
double s = (i0 >= 0) ? 1 : -1;
double erri1 = Math.Abs(i1 - i0);
double erri2 = Math.Abs(i2 - i0);
double R = (erri2 == 0) ? 1 : erri1 / erri2;
i0 = s * Math.Abs(i0) * tol / double.Epsilon;
if (i0 == 0) i0 = b - a;
return quadlStep(f, a, b, fa, fb, i0);
}
示例12: Execute
public override object Execute(MulticastDelegate dele, ParameterCollection parameters)
{
try
{
return dele.DynamicInvoke(parameters.AllParameterValues);
}
catch (Exception ex)
{
return this.ExecuteOnException(ex, parameters);
}
}
示例13: TrySetSlot
public static bool TrySetSlot(MulticastDelegate multicastDelegate, object[] a, int index, object o)
{
if (a[index] == null)
{
a[index] = o;
}
if (a[index] != null)
{
return false;
}
return false;
}
示例14: 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;
}
示例15: Clone
public MulticastDelegate Clone()
{
MulticastDelegate headClone = new MulticastDelegate(Target, Function);
MulticastDelegate prevClone = headClone;
MulticastDelegate current = headClone._next;
MulticastDelegate clone;
while (current != null)
{
clone = new MulticastDelegate(current.Target, current.Function);
clone._prev = prevClone;
prevClone = clone;
current = current._next;
}
return headClone;
}