本文整理汇总了C#中System.Invoke方法的典型用法代码示例。如果您正苦于以下问题:C# System.Invoke方法的具体用法?C# System.Invoke怎么用?C# System.Invoke使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System
的用法示例。
在下文中一共展示了System.Invoke方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AssignAllActions
void AssignAllActions(System.Action<BaseEventData> pressedAction,
System.Action<BaseEventData> releasedAction,
ref EventTrigger trigger)
{
EventTrigger.Entry entry1 = new EventTrigger.Entry();
entry1.eventID = EventTriggerType.PointerDown;
entry1.callback.AddListener(eventData => pressedAction.Invoke(eventData));
trigger.triggers.Add(entry1);
EventTrigger.Entry entry2 = new EventTrigger.Entry();
entry2.eventID = EventTriggerType.PointerUp;
entry2.callback.AddListener(eventData => releasedAction.Invoke(eventData));
trigger.triggers.Add(entry2);
EventTrigger.Entry entry3 = new EventTrigger.Entry();
entry3.eventID = EventTriggerType.PointerExit;
entry3.callback.AddListener(eventData => releasedAction.Invoke(eventData));
trigger.triggers.Add(entry3);
}
示例2: QueueUserWorkItem
public static void QueueUserWorkItem(System.Threading.WaitCallback callback)
{
if (Pool != null)
{
Pool.QueueWorkItem(state => { callback.Invoke(state); return null; });
}
else
{
System.Threading.ThreadPool.QueueUserWorkItem(state => callback.Invoke(state));
}
}
示例3: DelayExecute
public static void DelayExecute(System.Action callback, int msDelay, bool onUIThread = true)
{
Thread t = new Thread(delegate() {
Thread.Sleep(msDelay);
if (onUIThread)
Caliburn.Micro.Execute.OnUIThread(() => callback.Invoke());
else
callback.Invoke();
});
t.Start();
}
示例4: Invoke
public static object Invoke(System.Windows.Forms.Control obj, string methodName, params object[] paramValues)
{
Delegate del = null;
string key = obj.GetType().Name + "." + methodName;
Type tp;
lock (methodLookup)
{
if (methodLookup.Contains(key))
tp = (Type)methodLookup[key];
else
{
Type[] paramList = new Type[obj.GetType().GetMethod(methodName).GetParameters().Length];
int n = 0;
foreach (ParameterInfo pi in obj.GetType().GetMethod(methodName).GetParameters()) paramList[n++] = pi.ParameterType;
TypeBuilder typeB = builder.DefineType("Del_" + obj.GetType().Name + "_" + methodName, TypeAttributes.Class | TypeAttributes.AutoLayout | TypeAttributes.Public | TypeAttributes.Sealed, typeof(MulticastDelegate), PackingSize.Unspecified);
ConstructorBuilder conB = typeB.DefineConstructor(MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName, CallingConventions.Standard, new Type[] { typeof(object), typeof(IntPtr) });
conB.SetImplementationFlags(MethodImplAttributes.Runtime);
MethodBuilder mb = typeB.DefineMethod("Invoke", MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.HideBySig, obj.GetType().GetMethod(methodName).ReturnType, paramList);
mb.SetImplementationFlags(MethodImplAttributes.Runtime);
tp = typeB.CreateType();
methodLookup.Add(key, tp);
}
}
del = MulticastDelegate.CreateDelegate(tp, obj, methodName);
return obj.Invoke(del, paramValues);
}
示例5: Invoke
/// <summary>
/// Invokes the given action on the UI thread - if the current thread is the UI thread this will just invoke the action directly on
/// the current thread so it can be safely called without the calling method being aware of which thread it is on.
/// </summary>
public static void Invoke(System.Action action)
{
if (Dispatcher.CheckAccess())
action.Invoke();
else
Dispatcher.BeginInvoke(action);
}
示例6: Invoke
public static void Invoke(System.Windows.Forms.Control con, InvokeDelegate callback) {
if (con.InvokeRequired) {
con.Invoke(callback);
} else {
callback();
}
}
示例7: Invoke
public static void Invoke(System.Windows.Forms.Control Control, InvokeDelegate Delegate) {
if (Control.InvokeRequired) {
Control.Invoke(Delegate);
} else {
Delegate();
}
}
示例8: GetInstance
public override object GetInstance(System.Reflection.ConstructorInfo constructor, object[] parameters = null)
{
if (cache.ContainsKey(constructor.DeclaringType))
{
return cache[constructor.DeclaringType];
}
var dependencies = constructor.GetParameters();
if (dependencies.Count() == 0)
{
var instance = Activator.CreateInstance(constructor.DeclaringType);
cache.Add(constructor.DeclaringType, instance);
return instance;
}
else
{
if (parameters == null || parameters.Count() != dependencies.Count())
{
throw new Exception("Incorrect number of parameters to invoke instance.");
}
var instance = constructor.Invoke(parameters);
cache.Add(constructor.DeclaringType, instance);
return instance;
}
}
示例9: Authenticate
public void Authenticate(System.Action<bool> callback, bool silent)
{
LogUsage();
if (callback != null)
{
callback.Invoke(false);
}
}
示例10: UpdatePbar
public static void UpdatePbar(System.Windows.Forms.ProgressBar name, int step)
{
if (name.InvokeRequired)
{
object[] params_list = new object[] { name, step };
name.Invoke(new UpdateProgressBar(UpdatePbar), params_list);
}
else { name.Increment(step); }
}
示例11: SetText
public static void SetText(System.Windows.Forms.TextBox ctrl, string text)
{
if (ctrl.InvokeRequired)
{
object[] params_list = new object[] { ctrl, text };
ctrl.Invoke(new SetTextDelegate(SetText), params_list);
}
else { ctrl.AppendText(text); }
}
示例12: RunTestCase
internal void RunTestCase(System.Reflection.MethodInfo met)
{
var testInstance = Activator.CreateInstance(this.testCaseType);
if (this.setupMethod != null)
{
this.setupMethod.Invoke(testInstance, null);
}
met.Invoke(testInstance, null);
}
示例13: RunTest
public void RunTest (Test test, System.Reflection.MethodInfo method)
{
var startTime = DateTime.Now;
test.Setup ();
var attributes = (TestAttribute[])method.GetCustomAttributes (typeof(TestAttribute), false);
if (attributes[0].Async) {
try {
method.Invoke (test, new object[] { (AsyncCallback)(result =>
{
var t = (Test)((object[])result.AsyncState)[0];
var m = (System.Reflection.MethodInfo)((object[])result.AsyncState)[1];
var s = (DateTime)((object[])result.AsyncState)[2];
t.TearDown ();
if (OnTestFinished != null)
{
OnTestFinished (t, m, DateTime.Now - s, null);
}
}), new object[] { test, method, startTime } });
} catch (Exception ex)
{
if (OnTestFinished != null)
{
OnTestFinished(test, method, DateTime.Now - startTime, ex);
}
}
} else {
Exception ex = null;
try {
method.Invoke (test, null);
} catch (Exception e)
{
ex = e;
}
test.TearDown ();
if (OnTestFinished != null) {
OnTestFinished (test, method, DateTime.Now - startTime, ex);
}
}
}
示例14: Invoke
public virtual object Invoke(object proxy, System.Reflection.MethodInfo method, params object[] arguments)
{
PreInvoke(proxy, method, arguments);
object returnValue = method.Invoke( Target, arguments );
PostInvoke(proxy, method, ref returnValue, arguments);
return returnValue;
}
示例15: Invoke
public object Invoke(object target, System.Reflection.MethodInfo method, params object[] parameters)
{
Console.WriteLine("before call:"+method.Name);
object result = method.Invoke(target , parameters);
Console.WriteLine("after call:" + method.Name);
return result;
}