本文整理汇总了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
}
示例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
}
示例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()))
{
}