本文整理汇总了C#中this.CheckAccess方法的典型用法代码示例。如果您正苦于以下问题:C# this.CheckAccess方法的具体用法?C# this.CheckAccess怎么用?C# this.CheckAccess使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类this
的用法示例。
在下文中一共展示了this.CheckAccess方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NecessityInvoke
public static void NecessityInvoke(this Dispatcher self, Action action)
{
if (self.CheckAccess())
action();
self.Invoke(action);
}
示例2: adoptAsync
public static void adoptAsync(this Dispatcher dispatcher, Action del)
{
if(dispatcher.CheckAccess())
del();
else
dispatcher.BeginInvoke(del);
}
示例3: InvokeIfRequired
public static void InvokeIfRequired(this Dispatcher dispatcher, Action action, DispatcherPriority priority)
{
if (!dispatcher.CheckAccess())
dispatcher.Invoke(priority, (Delegate) action);
else
action();
}
示例4: InvokeOnUIThread
/// <summary>
/// Executes an action on the UI thread, waiting for the action to complete.<br/>
/// If this method is called from the UI thread, the action is executed immediately.<br/>
/// If the method is called from another thread, the action will be enqueued on the UI thread's dispatcher
/// and executed synchronously.
/// </summary>
/// <param name="dispatcher">Dispatcher instance.</param>
/// <param name="action">Action to execute.</param>
/// <exception cref="ArgumentNullException">
/// <paramref name="dispatcher"/> is <see langword="null"/>.
/// <para>-or-</para>
/// <paramref name="action"/> is <see langword="null"/>.
/// </exception>
public static void InvokeOnUIThread(this Dispatcher dispatcher, Action action)
{
if (dispatcher == null)
{
throw new ArgumentNullException("dispatcher");
}
if (action == null)
{
throw new ArgumentNullException("action");
}
if (dispatcher.CheckAccess())
{
action();
}
else
{
using (ManualResetEventSlim resetEvent = new ManualResetEventSlim(false))
{
dispatcher.BeginInvoke(() =>
{
action();
resetEvent.Set();
});
resetEvent.Wait();
}
}
}
示例5: VerifyAccess
/// <summary>
/// Determines whether the calling thread has access to this Dispatcher.
/// </summary>
/// <param name="dispatcher"></param>
/// <remarks>Only the thread the Dispatcher is created on may access the Dispatcher.
/// This method is public; therefore, any thread can check to see whether it has access to the Dispatcher.
/// The difference between CheckAccess and VerifyAccess is CheckAccess returns a Boolean if the calling thread does
/// not have access to the Dispatcher and VerifyAccess throws an exception.
///</remarks>
public static void VerifyAccess(this Dispatcher dispatcher)
{
if (!dispatcher.CheckAccess())
{
throw new InvalidOperationException("Cross-thread operation not valid");
}
}
示例6: SyncInvoke
public static void SyncInvoke(this Dispatcher dispatcher, Action action)
{
if (dispatcher.CheckAccess())
action();
else
dispatcher.Invoke(action);
}
示例7: BeginInvokeAfterTimeout
/// <summary>
/// Executes the specified action asynchronously on the thread the Dispatcher is associated with, after the specified timeout.
/// </summary>
/// <param name="dispatcher">The dispatcher instance.</param>
/// <param name="timeout">The <see cref="TimeSpan"/> representing the amount of time to delay before the action is invoked.</param>
/// <param name="action">The <see cref="Action"/> to execute.</param>
public static void BeginInvokeAfterTimeout(this Dispatcher dispatcher, TimeSpan timeout, Action action)
{
if (!dispatcher.CheckAccess())
{
dispatcher.BeginInvoke(() => dispatcher.BeginInvokeAfterTimeout(timeout, action));
}
else
{
var dispatcherTimer = new DispatcherTimer()
{
Interval = timeout
};
dispatcherTimer.Tick += (s, e) =>
{
dispatcherTimer.Stop();
dispatcherTimer = null;
action();
};
dispatcherTimer.Start();
}
}
示例8: GetPropertyValue
public static object GetPropertyValue(this DependencyObject o, DependencyProperty prop)
{
if (o.CheckAccess())
return o.GetValue(prop);
return o.Dispatcher.Invoke(new Func<DependencyObject, DependencyProperty, object>(GetPropertyValue),
o,
prop);
}
示例9: InvokeOrExecute
public static void InvokeOrExecute(this Dispatcher dispatcher, Action action)
{
if (dispatcher.CheckAccess()) {
action();
} else {
dispatcher.BeginInvoke(DispatcherPriority.Normal, action);
}
}
示例10: DoAsync
private static Task DoAsync(this Dispatcher dispatcher, Action action)
{
if (!dispatcher.CheckAccess())
{
return RunAsync(dispatcher, action);
}
return RunSynchronously(action);
}
示例11: CheckAccess
public static bool CheckAccess(this IAuthorizationService authorizationService, IPrincipal principal, Operation operation, Resource resource)
{
var claimsPrincipal = principal.AsClaimsPrincipal();
var resources = new Collection<Claim>(new Claim[] { resource }.ToList());
var operations = new Collection<Claim>(new Claim[] { operation }.ToList());
var authorizationContext = new AuthorizationContext(claimsPrincipal, resources, operations);
return authorizationService.CheckAccess(authorizationContext);
}
示例12: SetPropertyValue
public static void SetPropertyValue(this DependencyObject o, DependencyProperty prop, object value)
{
if (o.CheckAccess())
o.SetValue(prop, value);
else
o.Dispatcher.Invoke(new Action<DependencyObject, DependencyProperty, object>(SetPropertyValue),
o,
prop,
value);
}
示例13: Do
private static void Do(this Dispatcher dispatcher, Action action)
{
if (!dispatcher.CheckAccess())
{
dispatcher.BeginInvoke(action, DispatcherPriority.Background);
return;
}
action();
}
示例14: RunAsync
/// <summary>
/// Invokes the specified action asynchronously using the <see cref="Dispatcher"/> if required.
/// </summary>
/// <param name="dispatcher">The dispatcher.</param>
/// <param name="action">The action.</param>
/// <returns>A task containing the invoked action.</returns>
public static async Task RunAsync(this Dispatcher dispatcher, Action action)
{
if (dispatcher.CheckAccess())
{
action();
}
else
{
await dispatcher.InvokeAsync(() => RunAsync(dispatcher, action));
}
}
示例15: SmartBeginInvoke
public static void SmartBeginInvoke(this Dispatcher dispatcher, Action a)
{
if (dispatcher.CheckAccess())
{
a.Invoke();
}
else
{
dispatcher.BeginInvoke(a);
}
}