本文整理汇总了C#中System.Action.ExecuteIfNotNull方法的典型用法代码示例。如果您正苦于以下问题:C# Action.ExecuteIfNotNull方法的具体用法?C# Action.ExecuteIfNotNull怎么用?C# Action.ExecuteIfNotNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Action
的用法示例。
在下文中一共展示了Action.ExecuteIfNotNull方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SelectContactAddress
public static void SelectContactAddress(Action<string, Exception> addressSelected)
{
var task = new AddressChooserTask();
task.Completed += (s, e) => addressSelected.ExecuteIfNotNull(e.Address, e.Error);
task.Show();
}
示例2: RunWorker
/// <summary>
/// Invokes the given action on a background thread
/// </summary>
/// <param name="work">An action executed without UI access</param>
/// <param name="onCompleted">An action executed on the UI thread after work is completed</param>
public static void RunWorker(Action work, Action onCompleted)
{
// Don't do anything if the work action is empty
if (work == null)
{
return;
}
if (IsRunningOnUIThread)
{
// Spawn new thread only if UI is active
ThreadPool.QueueUserWorkItem(
workAction =>
{
((Action) workAction)();
InvokeAsync(onCompleted);
},
work
);
}
else
{
// Otherwise, just execute in linear fashion
work();
onCompleted.ExecuteIfNotNull();
}
}