当前位置: 首页>>代码示例>>C#>>正文


C# Delegate.DynamicInvoke方法代码示例

本文整理汇总了C#中System.Delegate.DynamicInvoke方法的典型用法代码示例。如果您正苦于以下问题:C# Delegate.DynamicInvoke方法的具体用法?C# Delegate.DynamicInvoke怎么用?C# Delegate.DynamicInvoke使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Delegate的用法示例。


在下文中一共展示了Delegate.DynamicInvoke方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DelayedInvoke

 /// <summary>
 /// Initializes a new instance of the <see cref="DelayedInvoke"/> class.
 /// </summary>
 /// <param name="action">The action to perform.</param>
 /// <param name="timeout">The timeout before running.</param>
 /// <param name="blocking">if set to <c>true</c> then the delay will block.</param>
 /// <param name="args">The arguments to pass to the action.</param>
 public DelayedInvoke(Delegate action, int timeout, bool blocking, object[] args = null)
 {
     if (timeout == 0)
     {
         action.DynamicInvoke(args);
     }
     if (blocking)
     {
         do
         {
             Restart = false;
             Thread.Sleep(timeout);
         } while (Restart);
         HasReturned = true;
         ReturnValue = action.DynamicInvoke(args);
     }
     else
     {
         thread = new Thread(delegate()
         {
             do
             {
                 Restart = false;
                 Thread.Sleep(timeout);
             } while (Restart);
             HasReturned = true;
             ReturnValue = action.DynamicInvoke(args);
         });
         thread.Name = "DelayedInvoke: " + action.Method.Name;
         thread.Start();
     }
 }
开发者ID:TGOSeraph,项目名称:StUtil,代码行数:39,代码来源:DelayedInvoke.cs

示例2: makeMethodCall

        public void makeMethodCall(Delegate methodToCall)
        {
            addArgsTextBox.Text = "Click new constructor or method.";
            object[] argObjects = new object[methodArgs.Count];
            if (argObjects.Length != methodToCall.Method.GetParameters().Length)
            {
                System.Windows.Forms.MessageBox.Show("Not enough arguments");
                methodArgs.Clear();
                enteredArgsLabel.Text = "Entered Args";
                return;
            }

            string stringType = "";
            int i = 0;
            ParameterInfo[] instancePars = methodToCall.Method.GetParameters();
            foreach (object ob in methodArgs)
            {
                if (ob != null)
                {
                    stringType = instancePars[i].ParameterType.Name;
                    try
                    {
                        argObjects[i] = parseObject(stringType, ob);
                    }
                    catch (Exception Exception)
                    {
                        System.Windows.Forms.MessageBox.Show("err: " + Exception.Message);
                        clearArgsButt_Click(null, null);
                        return;
                    }
                    i++;
                }
            }

            object[] returned = null;
            object returned_Temp = null;

            if (argObjects.Length == 0)
            {
                returned_Temp = methodToCall.DynamicInvoke();
            }
            else
            {
                returned_Temp = methodToCall.DynamicInvoke(argObjects);
            }

            if (methodToCall.Method.ReturnParameter.ParameterType != typeof(void))
            {
                returned = new object[1];
                returned[0] = returned_Temp;
            }

            if (returned != null)
            {
                objectsListBox.Items.Add(returned[0]);
            }

            enteredArgsLabel.Text = "Entered Args";
            methodArgs.Clear();
        }
开发者ID:GrayKernel,项目名称:GrayStorm,代码行数:60,代码来源:MethodEditor.cs

示例3: BeginInvoke

        /// <summary>
        /// Forwards the BeginInvoke to the current application's <see cref="Dispatcher"/>.
        /// </summary>
        /// <param name="method">Method to be invoked.</param>
        /// <param name="arg">Arguments to pass to the invoked method.</param>
        public Task BeginInvoke(Delegate method, params object[] arg)
        {
            if (dispatcher != null)
                return dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => method.DynamicInvoke(arg)).AsTask();

            var coreWindow = CoreApplication.MainView.CoreWindow;
            if (coreWindow != null)
            {
                dispatcher = coreWindow.Dispatcher;
                return dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => method.DynamicInvoke(arg)).AsTask();
            }
            else
                return Task.Delay(0);
        }
开发者ID:xperiandri,项目名称:PortablePrism,代码行数:19,代码来源:DefaultDispatcher.Desktop.cs

示例4: InvokeEvent

 /// <summary>
 /// Invokes a .NET event
 /// </summary>
 /// <param name="handler">Event to be invoked</param>
 /// <param name="args">Paramters to pass to the event</param>
 public void InvokeEvent(Delegate handler, params object[] args)
 {
     if (handler != null)
     {
         handler.DynamicInvoke(args);
     }
 }
开发者ID:darth10,项目名称:JSInterop,代码行数:12,代码来源:JavascriptHost.cs

示例5: Core_RunInGui

        public void Core_RunInGui(Delegate method, params object[] args)
        {
            if (method == null)
                return;

            RunOnUiThread(new Action(() => method.DynamicInvoke(args)));
        }
开发者ID:swax,项目名称:DeOps,代码行数:7,代码来源:Activity1.cs

示例6: DoInvoke

 private object DoInvoke(Guid relatedActivityId, Delegate method, object[] methodArgs)
 {
     using (_eventCorrelator.StartActivity(relatedActivityId))
     {
         return method.DynamicInvoke(methodArgs);
     }
 }
开发者ID:40a,项目名称:PowerShell,代码行数:7,代码来源:EtwActivityReverterMethodInvoker.cs

示例7: Invoke

        public object Invoke(Delegate method, params object[] args)
        {
            object result = null;
            Exception exception = null;

            using (ManualResetEvent waitHandle = new ManualResetEvent(false))
            {
                _queue._queue.Enqueue(
                    delegate()
                    {
                        try
                        {
                            result = method.DynamicInvoke(args);
                        }
                        catch (Exception e)
                        {
                            exception = e;
                        }

                        waitHandle.Set();
                    });

                waitHandle.WaitOne();
            }

            if (exception != null)
            {
                throw new ReactorInvocationException("An exception occurred invoking a method " +
                    "in a reactor thread; check InnerException for the exception.", exception);
            }
            else
            {
                return result;
            }
        }
开发者ID:gregorypilar,项目名称:interlace,代码行数:35,代码来源:BlockingReactorThreadInvoker.cs

示例8: BeginInvoke

 /// <summary>
 /// Forwards the BeginInvoke to the current application's <see cref="Dispatcher"/>.
 /// </summary>
 /// <param name="method">Method to be invoked.</param>
 /// <param name="arg">Arguments to pass to the invoked method.</param>
 public void BeginInvoke(Delegate method, object arg)
 {
     if (Application.Current != null)
     {
         Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, method, arg);
     }
     else if (SynchronizationContext.Current != null)
     {
         SendOrPostCallback callback = new SendOrPostCallback(delegate { method.DynamicInvoke(arg); });
         SynchronizationContext.Current.Post(callback, null);
     }
     else
     {
         method.DynamicInvoke(arg);
     }    
 }
开发者ID:jeffras,项目名称:Prism-4-with-WinForms,代码行数:21,代码来源:DefaultDispatcher.Desktop.cs

示例9: Execute

		/// <summary>Invokes the specified delegate with the specified parameters in the specified kind of apartment state.</summary>
		/// <param name="d">The delegate to be invoked.</param>
		/// <param name="parameters">The parameters to pass to the delegate being invoked.</param>
		/// <param name="state">The apartment state to run under.</param>
		/// <returns>The result of calling the delegate.</returns>
		public static object Execute(
			Delegate d, object[] parameters, ApartmentState state)
		{
			if (d == null) throw new ArgumentNullException("d");
			if (state != ApartmentState.MTA && state != ApartmentState.STA)
				throw new ArgumentOutOfRangeException("state");

			if (Thread.CurrentThread.ApartmentState == state)
			{
				return d.DynamicInvoke(parameters);
			}
			else
			{
				ApartmentStateSwitcher switcher = new ApartmentStateSwitcher();
				switcher._delegate = d;
				switcher._parameters = parameters;

				Thread t = new Thread(new ThreadStart(switcher.Run));
				t.ApartmentState = state;
				t.IsBackground = true;
				t.Start();
				t.Join();

				if (switcher._exc != null) throw switcher._exc;
				return switcher._rv;
			}
		}
开发者ID:babgvant,项目名称:EVRPlay,代码行数:32,代码来源:ApartmentStateSwitcher.cs

示例10: ExecuteDelegate

 /// <summary>
 ///   Executes the specified delegate on the UI thread
 /// </summary>
 /// <param name="del"> </param>
 /// <param name="arguments"> </param>
 public static void ExecuteDelegate(Delegate del, params object[] arguments) {
     if (CheckAccess()) {
         del.DynamicInvoke(arguments);
     } else {
         UserInterfaceDispatcher.BeginInvoke(del, arguments);
     }
 }
开发者ID:Sebazzz,项目名称:SDammann.WindowsPhone.Utils,代码行数:12,代码来源:UserInterfaceThreadDispatcher.cs

示例11: Cache

        public static object Cache(string key, int cacheTimeMilliseconds, Delegate result, params object[] args)
        {
            var cache = MemoryCache.Default;

            if (cache[key] == null)
            {
                object cacheValue;
                try
                {
                    if (result == null)
                        return null;
                    cacheValue = result.DynamicInvoke(args);
                }
                catch (Exception e)
                {

                    var message = e.InnerException.GetBaseException().Message;
                    throw new CacheDelegateMethodException(message);

                }
                if (cacheValue != null)
                {
                    cache.Set(key, cacheValue, DateTimeOffset.Now.AddMilliseconds(cacheTimeMilliseconds));
                }
            }
            return cache[key];
        }
开发者ID:brentonmcs,项目名称:CacheController,代码行数:27,代码来源:CachingService.cs

示例12: Delete

        public static string Delete(int id, Delegate del, string ItemType)
        {
            var message = string.Empty;
            var sqlError = string.Empty;
            var errorMessage = string.Format("Error deleting {0} item (id={1}).", ItemType, id);

            try
            {
                var r = del.DynamicInvoke(id, sqlError);

                //Return actual error message, if any
                if (!string.IsNullOrEmpty(sqlError))
                    throw new Exception(errorMessage += " " + sqlError);
                else if ((int)r != 0)
                    throw new Exception(string.Format("{0} {1} returned {2}.", errorMessage, del.Method.Name, r));
            }
            catch (Exception exc)
            {
                message = errorMessage;
                Global.logger.ErrorException(message, exc);
                throw;
            }

            return message;
        }
开发者ID:dineshkummarc,项目名称:TigerWrestling,代码行数:25,代码来源:BaseService.cs

示例13: Call5

        public string Call5(Delegate callback)
        {
            var thisArg = JsValue.Undefined;
            var arguments = new JsValue[] { 1, "foo" };

            return callback.DynamicInvoke(thisArg, arguments).ToString();
        }
开发者ID:Willy-Kimura,项目名称:jint,代码行数:7,代码来源:A.cs

示例14: Invoke

 public object Invoke(Delegate method, object[] args)
 {
     //Uses NSObject.InvokeOnMainThread
     object result = null;
     InvokeOnMainThread (() => result = method.DynamicInvoke (args));
     return result;
 }
开发者ID:tranuydu,项目名称:prebuilt-apps,代码行数:7,代码来源:SynchronizeInvoke.cs

示例15: InvokeUntypedDelegate

        public static void InvokeUntypedDelegate(Delegate d, params object[] args) {
#if SILVERLIGHT
            IronPython.Runtime.Operations.PythonCalls.Call(d, args);
#else
            d.DynamicInvoke(args);
#endif
        }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:7,代码来源:DelegateTest.cs


注:本文中的System.Delegate.DynamicInvoke方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。