DynamicInvoke() публичный Метод

public DynamicInvoke ( ) : object
Результат object
Пример #1
0
 /// <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();
     }
 }
 public void CallFunction()
 {
     try
     {
         System.Delegate v_tempFunctionPointer = FunctionToCall;
         object[]        v_params = Parameters.ToArray();
         if (ClearFunctionWhenFinish)
         {
             FunctionToCall = null;
             Parameters.Clear();
         }
         if (v_tempFunctionPointer != null)
         {
             if (Parameters.Count == 0)
             {
                 v_tempFunctionPointer.DynamicInvoke(null);
             }
             else
             {
                 v_tempFunctionPointer.DynamicInvoke(v_params);
             }
         }
     }
     catch
     {
         FunctionToCall = null;
         Parameters.Clear();
     }
 }
Пример #3
0
        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();
        }
        private void datagridHoldInvoice_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            DataGridRow row = ItemsControl.ContainerFromElement((DataGrid)sender, e.OriginalSource as DependencyObject) as DataGridRow;

            if (row == null)
            {
                return;
            }

            _delegateInvoiceOpen.DynamicInvoke();
        }
        /// <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);
        }
 public Object Execute(System.Delegate Method, params object[] Arguments)
 {
     if (Method == null)
     {
         throw new InvalidOperationException();
     }
     else if (!this.Open())
     {
         throw new InvalidOperationException("Could not open security context.");
     }
     else
     {
         try
         {
             this._Executing = true;
             Object ReturnValue = Method.DynamicInvoke(Arguments);
             this.Close();
             this._Executing = false;
             return(ReturnValue);
         }
         catch (Exception e)
         {
             return(null);
         }
     }
 }
Пример #7
0
    public void Memorize(string name, object memory, bool is_writable = false)
    {
        if (memory is System.Delegate && !(memory is System.Func <object>))
        {
            System.Delegate delegate_ = memory as System.Delegate;
            if (delegate_.Method.GetParameters().Count() == 0)
            {
                memory = (System.Func <object>)(() => delegate_.DynamicInvoke());
            }
        }

        if (is_writable)
        {
            memories[name] = new WritableVariable(name, memory);
        }
        else if (memory is System.Func <object> )
        {
            memories[name] = new FunctionVariable(name, memory as System.Func <object>);
        }
        else
        {
            memories[name] = new ReadOnlyVariable(name, memory);
        }

        memory_names[memories[name]] = name;
    }
Пример #8
0
		/////////////////////////////////////////////////////////////////////////////

		public static object Invoke( Delegate dg, object [] args )
		{
			// ******
			if( null == dg ) {
				throw new ArgumentNullException( "delegate" );
			}

			// ******
			MethodInfo mi = dg.Method;
			object [] newArgs = MatchArgs( mi, args );
			if( null == newArgs ) {
				//
				// could not match arguments
				//
				ThreadContext.MacroError( "could not match the parameters for delegate \"{0}\" with the argument types {1} on the object type \"{2}\"", dg.Method.Name, Arguments.ObjectsTypeNames( args ), GetDeclaringTypeName( dg ) );
			}

			// ******
			try {
				return dg.DynamicInvoke( newArgs );
			}
			catch( Exception ex ) {
				//
				// never returns
				//
				//ThreadContext.MacroError( "{0}.DynamicInvoke() failed: {1}", mi.Name, ex.Message );
				string msg = ExceptionHelpers.RecursiveMessage( ex, "{0}.DynamicInvoke() failed: {1}", mi.Name, ex.Message );
				ThreadContext.MacroError( msg );
				return null;
			}
		}
        public virtual Object Execute(System.Delegate Method, params object[] Arguments)
        {
            if (this.IsExecuting)
            {
                throw new InvalidOperationException("UserImpersonator cannot Execute while another execution is already in progress.");
            }
            else if (Method == null)
            {
                throw new InvalidOperationException("UserImpersonator cannot Execute without a supplied, or stored Method to invoke.");
            }
            else if (!this.Open())
            {
                throw new InvalidOperationException("Could not open security context.");
            }
            else
            {
                try
                {
                    this._IsExecuting = true;

                    Object ReturnValue = Method.DynamicInvoke(Arguments);

                    this.Close();

                    this._IsExecuting = false;

                    return(ReturnValue);
                }
                catch (Exception e)
                {
                    return(null);
                }
            }
        }
Пример #10
0
        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;
        }
Пример #11
0
 protected void doComplete()
 {
     if (_method != null)
     {
         _method.DynamicInvoke(_parameters);
     }
 }
Пример #12
0
 public object Invoke(Delegate method, object[] args)
 {
     //Uses NSObject.InvokeOnMainThread
     object result = null;
     InvokeOnMainThread (() => result = method.DynamicInvoke (args));
     return result;
 }
        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;
            }
        }
 private object DoInvoke(Guid relatedActivityId, Delegate method, object[] methodArgs)
 {
     using (_eventCorrelator.StartActivity(relatedActivityId))
     {
         return method.DynamicInvoke(methodArgs);
     }
 }
        static internal void ExecuteAndSendResult(Binder binder, System.Delegate callback, object[] arguments, double id, bool execute, bool isDynamic)
        {
            object result = null;

            if (execute)
            {
                if (!isDynamic)
                {
                    foreach (var invocation in callback.GetInvocationList())
                    {
                        result = invocation.Method.Invoke(invocation.Target, arguments);
                    }
                }
                else
                {
                    result = callback.DynamicInvoke(arguments);
                }
                if (result != null && id != 0)
                {
                    binder.Return(id, result);
                }
            }
            else
            {
                binder.SendError();
            }
        }
 /// <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);
     }    
 }
 /// <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);
     }
 }
Пример #18
0
        public static void InvokeUntypedDelegate(Delegate d, params object[] args) {
#if SILVERLIGHT
            IronPython.Runtime.Operations.PythonCalls.Call(d, args);
#else
            d.DynamicInvoke(args);
#endif
        }
Пример #19
0
 /// <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);
     }
 }
Пример #20
0
        public void Core_RunInGui(Delegate method, params object[] args)
        {
            if (method == null)
                return;

            RunOnUiThread(new Action(() => method.DynamicInvoke(args)));
        }
Пример #21
0
        public void FireEvent(object key, EventArgs e)
        {
            System.Delegate delegateToInvoke = (System.Delegate)Events[key];

            if (delegateToInvoke != null)
            {
                try
                {
                    delegateToInvoke.DynamicInvoke(GetEventSender(), e);
                }
                catch (Exception ex)
                {
                    // Note: this check is for the debugger, so we can catch exceptions in the debugger instead of
                    // throwing a thread exception.
                    if (NativeWindow.WndProcShouldBeDebuggable)
                    {
                        throw;
                    }
                    else
                    {
                        Application.OnThreadException(ex);
                    }
                }
            }
        }
Пример #22
0
		/// <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;
			}
		}
Пример #23
0
 public static void DynamicInvokeSafely(this System.Delegate @delegate, params object[] args)
 {
     if (@delegate != null)
     {
         @delegate.DynamicInvoke(args);
     }
 }
Пример #24
0
        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];
        }
Пример #25
0
        public string Call5(Delegate callback)
        {
            var thisArg = JsValue.Undefined;
            var arguments = new JsValue[] { 1, "foo" };

            return callback.DynamicInvoke(thisArg, arguments).ToString();
        }
Пример #26
0
	// Execute a delegate on the event listening thread.
	public static void InvokeOnEventsThread(Delegate method)
			{
				// There is no event thread, so execute the delegate here.
				if(method != null)
				{
					method.DynamicInvoke(new Object [0]);
				}
			}
Пример #27
0
        private void label5_Click(object sender, EventArgs e)
        {
            int indexOfControl = index;

            _delPageMethod.DynamicInvoke(indexOfControl);

            this.Dispose();
        }
Пример #28
0
 private static void ChangeAllLampState(Delegate stateChange)
 {
     foreach (HueLamp lamp in lamps.Values)
     {
         stateChange.DynamicInvoke(lamp);
     }
     messaging.SendMessage(lamps.Values.ToList<HueLamp>());
 }
Пример #29
0
 /// <summary>
 /// Runs the given delegates with the given arguments in a new thread
 /// </summary>
 public void LoadScreenContent(Delegate loadMethod, Delegate completeMethod, object[] loadArgs)
 {
     // Invokes load then close delegates in a new thread.
     // TODO: Remove thread sleep once loading testing is complete
     loadingThread = new Thread(() => { /* Thread.Sleep(1000); */ loadMethod.DynamicInvoke(loadArgs); completeMethod.DynamicInvoke(); });
     loadingThread.Priority = ThreadPriority.Highest;
     loadingThread.Start();
 }
Пример #30
0
 public static void Invoke(this FrameworkElement element, Delegate action, params object[] values)
 {
     if (element.InvokeRequired())
     {
         using (AutoResetEvent are = new AutoResetEvent(false))
         {
             Deployment.Current.Dispatcher.BeginInvoke(() =>
             {
                 action.DynamicInvoke(values);
                 are.Set();
             });
             are.WaitOne();
         }
     }
     else
         action.DynamicInvoke(values);
 }
Пример #31
0
        public IAsyncResult BeginInvoke(Delegate method, object[] args)
        {
            Application.Invoke (delegate {
                method.DynamicInvoke (args);
            });

            return null;
        }
Пример #32
0
    private void InvokeDelegate(Delegate handler, object[] e)
    {
      ISynchronizeInvoke synchronizer = (ISynchronizeInvoke)handler.Target;

      if (synchronizer == null)
      {
        handler.DynamicInvoke(e);
        return;
      }

      if (synchronizer.InvokeRequired == false)
      {
        handler.DynamicInvoke(e);
        return;
      }

      synchronizer.Invoke(handler, e);
    }
Пример #33
0
		public static object SafeInvoke(Delegate delegateToFire, params object[] parameters )
		{	
			ISynchronizeInvoke invoker = delegateToFire.Target as ISynchronizeInvoke; 
			object retval=null;	

			if (invoker != null) 
			{									
				if (invoker.InvokeRequired) 
					retval = invoker.Invoke(delegateToFire, parameters); 
				else 
					retval = delegateToFire.DynamicInvoke( parameters ); 										
			}			
			else
			{
				retval = delegateToFire.DynamicInvoke( parameters );
			}
			return retval;
		}			
Пример #34
0
 public void ChangeAllLampStates(Delegate stateChange)
 {
     List<Lamp> lamps = messaging.DownloadLampList();
     foreach (Lamp lamp in lamps)
     {
         stateChange.DynamicInvoke(lamp);
     }
     messaging.SendMessage(lamps);
 }
Пример #35
0
		protected virtual void InvokeEventHandler (Delegate genericHandler, object genericTarget)
		{
			if (genericHandler == null)
				throw new ArgumentNullException ("genericHandler");
			if (genericTarget == null)
				throw new ArgumentNullException ("genericTarget");

			genericHandler.DynamicInvoke (genericTarget, this);
		}
 /// <summary>
 /// Forwards the BeginInvoke to the current deployment's <see cref="System.Windows.Threading.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 (Deployment.Current != null)
     {
         return Deployment.Current.Dispatcher.InvokeAsync(() => method.DynamicInvoke(arg));
     }
     else
         return Task.Delay(0);
 }
Пример #37
0
        public override void stop()
        {
            base.stop();

            if (m_callback != null)
            {
                m_callback.DynamicInvoke();
            }
        }
        /// <summary>
        /// Executes the specified delegate with the specified arguments synchronously on the thread the Dispatcher is associated with.
        /// </summary>
        /// <param name="dispatcher">The dispatcher.</param>
        /// <param name="method">A delegate to a method that takes parameters specified in args, which is pushed onto the Dispatcher event queue.</param>
        /// <param name="args">An array of objects to pass as arguments to the given method. Can be <c>null</c>.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="method" /> is <c>null</c>.</exception>
        /// <remarks>For target frameworks where the <see cref="Dispatcher" /> class does not contain the <c>Invoke</c> method, the <c>BeginInvoke</c>
        /// method will be used instead.</remarks>
        public static void Invoke(this Dispatcher dispatcher, Delegate method, params object[] args)
        {
            Argument.IsNotNull("method", method);

            if (dispatcher != null && !dispatcher.CheckAccess())
            {
#if NET
                dispatcher.Invoke(method, args);
#elif NETFX_CORE
                dispatcher.BeginInvoke(() => method.DynamicInvoke(args));
#else
                dispatcher.BeginInvoke(method, args);
#endif
            }
            else
            {
                method.DynamicInvoke(args);
            }
        }
Пример #39
0
        public static void Cancel(Delegate networkDel)
        {
            // stop listening
            mic.Stop();

            NetworkHelper.CancelSpeech();
            networkDel.DynamicInvoke(false, null);

            speechOperationInProgress = false;
        }
Пример #40
0
        public static object GetInsertCacheItem(System.Web.Caching.Cache cache, string key, Delegate action, object[] args, bool flushCache = false)
        {
            var cacheItem = cache[key];
              if (cacheItem != null && !flushCache) return cacheItem;

              cacheItem = action.DynamicInvoke(args);
              cache.Insert(key, cacheItem);

              return cacheItem;
        }
Пример #41
0
        public Task <bool> CanFire(WorkflowContext context)
        {
            var values = parameters.Select((x, i) => context.GlobalParameters.GetContextProperty(x.ContextPath, typeMap[i]))
                         .ToArray();


            var result = (bool)function.DynamicInvoke(values);

            return(Task.FromResult(result));
        }
 protected object Invoke(Delegate method, params object[] args)
 {
     var Owner = this.Owner;
     if (Owner == null)
         return method.DynamicInvoke(args);
     else
     {
         return Owner.Dispatcher.Invoke(method, args);
     }
 }
Пример #43
0
            private Expression Evaluate(Expression e)
            {
                if (e.NodeType == ExpressionType.Constant)
                {
                    return(e);
                }
                LambdaExpression lambda = Expression.Lambda(e);

                System.Delegate fn = lambda.Compile();
                return(Expression.Constant(fn.DynamicInvoke(null), e.Type));
            }
Пример #44
0
 protected bool CallDelegateFunction()
 {
     try
     {
         System.Delegate v_tempFunctionPointer = DelegatePointer;
         object[]        v_params = Params.ToArray();
         if (v_tempFunctionPointer != null)
         {
             if (Params.Count == 0)
             {
                 v_tempFunctionPointer.DynamicInvoke(null);
             }
             else
             {
                 v_tempFunctionPointer.DynamicInvoke(v_params);
             }
             return(true);
         }
     }
     catch { }
     return(false);
 }
Пример #45
0
 /// <summary>
 /// Only use the Dispatcher if we are not already on the UI Thread.
 /// This avoid WPF exceptions saying the dispatcher is unavailable.
 /// </summary>
 /// <param name="d">The delegate to invoke</param>
 /// <param name="args">Optional parameters</param>
 public static object Invoke(System.Delegate d, params object[] args)
 {
     if (dispatcher != null && System.Threading.Thread.CurrentThread.ManagedThreadId != uiThreadId)
     {
         // Note: must be careful using this method, it could deadlock the UI, so make sure
         // it cannot be interleaved with similar calls.
         return(dispatcher.Invoke(d, args));
     }
     else
     {
         // we are already on the UI thread so call the delegate directly.
         return(d.DynamicInvoke(args));
     }
 }
Пример #46
0
 private object DynamicInvokeCommand(System.Delegate commandDelegate, object[] agrs)
 {
     // execute
     try
     {
         object ret = commandDelegate.DynamicInvoke(agrs);
         return(ret);
     }
     catch (Exception exc)
     {
         // throw inner exception if exists
         throw (exc.InnerException != null ? exc.InnerException: exc);
     }
 }
Пример #47
0
 static public int DynamicInvoke(IntPtr l)
 {
     try {
         System.Delegate self = (System.Delegate)checkSelf(l);
         System.Object[] a1;
         checkParams(l, 2, out a1);
         var ret = self.DynamicInvoke(a1);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Пример #48
0
        internal static void Consume <T>(this IEvent @event, T t, System.Reflection.ParameterInfo[] parameterInfo = null)
        {
            if (IEventExtensions.IsNull(@event))
            {
                return;
            }

            System.Reflection.MethodInfo mi = @event.Source.Method;

            System.Reflection.ParameterInfo[] methodParams = parameterInfo ?? mi.GetParameters();

            System.Delegate @delegate = System.Delegate.CreateDelegate(typeof(T), mi);

            @delegate.DynamicInvoke();
        }
Пример #49
0
 static int DynamicInvoke(IntPtr L)
 {
     try
     {
         int             count = LuaDLL.lua_gettop(L);
         System.Delegate obj   = (System.Delegate)ToLua.CheckObject <System.Delegate>(L, 1);
         object[]        arg0  = ToLua.ToParamsObject(L, 2, count - 1);
         object          o     = obj.DynamicInvoke(arg0);
         ToLua.Push(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Пример #50
0
 /// <summary>
 /// Only use the Dispatcher if we are not already on the UI Thread.
 /// This avoid WPF exceptions saying the dispatcher is unavailable.
 /// </summary>
 /// <param name="d">The delegate to invoke</param>
 /// <param name="args">Optional parameters</param>
 public static object BeginInvoke(System.Delegate d, params object[] args)
 {
     if (dispatcher != null && System.Threading.Thread.CurrentThread.ManagedThreadId != uiThreadId)
     {
         // Note: we cannot use dispatcher.Invoke because that can lead to deadlocks.
         // For example, if this is a background thread with a lock() on a money data object
         // (like account.rebalance does) then UI thread might be blocked on trying to get
         // that lock and this dispatcher invoke would therefore create a deadlock.
         return(dispatcher.BeginInvoke(d, args));
     }
     else
     {
         // we are already on the UI thread so call the delegate directly.
         return(d.DynamicInvoke(args));
     }
 }
Пример #51
0
    static int DynamicInvoke(IntPtr L)
    {
        int count = LuaDLL.lua_gettop(L);

        System.Delegate obj  = (System.Delegate)ToLua.CheckObject(L, 1, typeof(System.Delegate));
        object[]        arg0 = ToLua.ToParamsObject(L, 2, count - 1);
        object          o    = null;

        try
        {
            o = obj.DynamicInvoke(arg0);
        }
        catch (Exception e)
        {
            return(LuaDLL.luaL_error(L, e.Message));
        }

        ToLua.Push(L, o);
        return(1);
    }
Пример #52
0
        public void BeginInvoke(System.Delegate aDelegate, params object[] aArgs)
        {
            iHandler.Post((Action)(() =>
            {
                try
                {
#if DEBUG || TRACE
                    Linn.Trace.WriteLine(Linn.Trace.kGui, string.Format("{0} INVOKING {1}", DateTime.Now.ToString(), this.GetCallInfo(aDelegate, aArgs)));
#endif
                    aDelegate.DynamicInvoke(aArgs);
#if DEBUG || TRACE
                    Linn.Trace.WriteLine(Linn.Trace.kGui, string.Format("{0} INVOKED {1}", DateTime.Now.ToString(), this.GetCallInfo(aDelegate, aArgs)));
#endif
                }
                catch (System.Exception ex)
                {
                    UserLog.WriteLine("Exception: " + ex);
                    UserLog.WriteLine("Invocation details: " + this.GetCallInfo(aDelegate, aArgs));
                    ThrowException(ex);
                }
            }));
        }
Пример #53
0
 public static void DynamicInvokeAbi(this System.Delegate del, object[] invoke_params)
 {
     Marshal.ThrowExceptionForHR((int)del.DynamicInvoke(invoke_params));
 }
Пример #54
0
 static System.Action Curry <T1, T2, T3, T4>(System.Delegate action, T1 t1, T2 t2, T3 t3, T4 t4)
 {
     return(() => action.DynamicInvoke(t1, t2, t3, t4));
 }
 protected void btnCancel_Click(object sender, EventArgs e)
 {
     _closeParam.DynamicInvoke();
 }
Пример #56
0
 static System.Action Curry <T1, T2>(System.Delegate action, T1 t1, T2 t2)
 {
     return(() => action.DynamicInvoke(t1, t2));
 }