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


C# Action.NullReference方法代码示例

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


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

示例1: Invoke

        /// <summary>
        /// Executes the specified <see cref="Action"/> synchronously on the UI thread.
        /// </summary>
        /// <param name="action">The delegate to invoke.</param>
        public void Invoke( Action action )
        {
            if( action.NullReference() )
                throw new ArgumentNullException().StoreFileLine();

#if !SILVERLIGHT
            this.dispatcher.Invoke(action, this.priority);
#else
            // NOTE: code segment originally from Caliburn.Micro
            var waitHandle = new ManualResetEvent(initialState: false); // initialState = non-signaled
            Exception exception = null;
            this.dispatcher.BeginInvoke(() =>
            {
                try
                {
                    action();
                }
                catch( Exception ex )
                {
                    exception = ex;
                }
                waitHandle.Set();
            });

            waitHandle.WaitOne();
            if( exception.NotNullReference() )
                throw new System.Reflection.TargetInvocationException("An error occurred while dispatching a call to the UI Thread", exception).StoreFileLine();
#endif
        }
开发者ID:MechanicalMen,项目名称:Mechanical2,代码行数:33,代码来源:DispatcherUIHandler.cs

示例2: InvokeAsync

        /// <summary>
        /// Executes the specified <see cref="Action"/> asynchronously on the UI thread.
        /// </summary>
        /// <param name="action">The delegate to invoke.</param>
        /// <returns>The <see cref="Task"/> representing the operation.</returns>
        public Task InvokeAsync( Action action )
        {
            if( action.NullReference() )
                throw new ArgumentNullException().StoreFileLine();

#if MECHANICAL_NET4
            var tsc = new TaskCompletionSource<object>();
            action = () =>
            {
                try
                {
                    action();
                    tsc.SetResult(null); // the Completed event would probably work just as well
                }
                catch( Exception ex )
                {
                    tsc.SetException(ex);
                }
            };
            var op = this.dispatcher.BeginInvoke(action, this.priority, Parameters);
            op.Aborted += ( s, e ) => tsc.SetCanceled(); // DispatcherOperations can be aborted, before code starts executing (since we don't keep a reference to it, this should only happen if the Dispatcher is shut down, before execution starts)
            return tsc.Task;
#elif SILVERLIGHT
            var tsc = new TaskCompletionSource<object>();
            var op = this.dispatcher.BeginInvoke(() =>
            {
                try
                {
                    action();
                    tsc.SetResult(null);
                }
                catch( Exception ex )
                {
                    tsc.SetException(ex);
                }
            });
            return tsc.Task;
#else
            return this.dispatcher.InvokeAsync(action, this.priority).Task;
#endif
        }
开发者ID:MechanicalMen,项目名称:Mechanical2,代码行数:46,代码来源:DispatcherUIHandler.cs

示例3: DelegateCommand

 /// <summary>
 /// Initializes a new instance of the <see cref="DelegateCommand"/> class.
 /// </summary>
 /// <param name="execute">The delegate invoked by Execute.</param>
 /// <param name="canExecute">The delegate invoked by CanExecute.</param>
 public DelegateCommand( Action execute, Func<bool> canExecute = null )
     : this(
         execute.NullReference() ? (Action<object>)null : new Action<object>(param => execute()),
         canExecute.NullReference() ? (Func<object, bool>)null : new Func<object, bool>(param => canExecute()))
 {
 }
开发者ID:MechanicalMen,项目名称:Mechanical2,代码行数:11,代码来源:DelegateCommand.cs


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