本文整理汇总了C#中this.BeginInvoke方法的典型用法代码示例。如果您正苦于以下问题:C# this.BeginInvoke方法的具体用法?C# this.BeginInvoke怎么用?C# this.BeginInvoke使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类this
的用法示例。
在下文中一共展示了this.BeginInvoke方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Invoke
public static void Invoke(this Control uiElement, Action updater, bool forceSynchronous = true)
{
if (uiElement == null)
{
throw new ArgumentNullException("uiElement");
}
if (uiElement.InvokeRequired)
{
if (forceSynchronous)
{
try
{
uiElement.Invoke((Action)delegate { Invoke(uiElement, updater, forceSynchronous); });
}
catch (Exception e) { }
}
else
{
uiElement.BeginInvoke((Action)delegate { Invoke(uiElement, updater, forceSynchronous); });
}
}
else
{
if (!uiElement.IsDisposed)
{
updater();
}
}
}
示例2: Invoke
public static void Invoke(this UserControl c, Action a)
{
if (!c.InvokeRequired)
a();
else if (!c.IsDisposed && !c.Disposing && c.Created)
c.BeginInvoke(a);
}
示例3: InvokeOnUiThreadIfRequired
/*
* Executes the action asynchronously on the UI thread, without blocking the calling thread.
*/
internal static void InvokeOnUiThreadIfRequired(this Control control, Action action) {
if(control.InvokeRequired) {
control.BeginInvoke(action);
} else {
action.Invoke();
}
}
示例4: 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();
}
}
示例5: FireAndForget
public static void FireAndForget(this Action action, object state = null)
{
lock (_invokedActions)
{
_invokedActions.Add(action.BeginInvoke(Forget, state), action);
}
}
示例6: InvokeAsynchronouslyInBackground
/// <summary>
/// A simple threading extension method, to invoke a delegate
/// on the correct thread asynchronously if it is not currently
/// on the correct thread which can be used with DispatcherObject types.
/// </summary>
/// <param name="dispatcher">The Dispatcher object on which to
/// perform the Invoke</param>
/// <param name="action">The delegate to run</param>
public static void InvokeAsynchronouslyInBackground(this Dispatcher dispatcher, Action action)
{
if (dispatcher != null)
dispatcher.BeginInvoke(DispatcherPriority.Background, action);
else
action();
}
示例7: SafeInvoke
/// <summary>
/// Функция упрощающая использование Invoke() для Windows Forms приложений
/// </summary>
/// <param name="ctrl">Элемент управления для которого необходимо вызвать Invoke()</param>
/// <param name="cmd"></param>
/// <example>myCtrl.SafeInvoke(() => myCtrl.Enabled = false);</example>
public static void SafeInvoke(this Control ctrl, Action cmd)
{
if (ctrl.InvokeRequired)
ctrl.BeginInvoke(cmd);
else
cmd();
}
示例8: PerformOnMainThread
public static void PerformOnMainThread(this Control control, Action action)
{
if (control.InvokeRequired)
control.BeginInvoke(action);
else
action();
}
示例9: SetText
/// <summary>
/// Set text to the control thread-safely.
/// </summary>
/// <param name="c"></param>
/// <param name="m"></param>
public static void SetText(this Control c, string m)
{
if (c.InvokeRequired)
c.BeginInvoke(new MethodInvoker(() => { c.Text = m; }));
else
c.Text = m;
}
示例10: adoptAsync
public static void adoptAsync(this Dispatcher dispatcher, Action del)
{
if(dispatcher.CheckAccess())
del();
else
dispatcher.BeginInvoke(del);
}
示例11: adoptAsync
public static void adoptAsync(this Dispatcher dispatcher, Action del)
{
if (Thread.CurrentThread == dispatcher.Thread)
del();
else
dispatcher.BeginInvoke(del);
}
示例12: BeginInvoke
public static void BeginInvoke(this Control control, Action action)
{
if (control.InvokeRequired)
control.BeginInvoke(action);
else
action();
}
示例13: SafeInvoke
public static void SafeInvoke(this Control ui_element,
Action updater, bool force_synchronous)
{
if (ui_element == null)
return;
if (ui_element.InvokeRequired) {
if (force_synchronous) {
ui_element.Invoke ((Action) delegate {
SafeInvoke (ui_element, updater, force_synchronous);
});
} else {
ui_element.BeginInvoke ((Action) delegate {
SafeInvoke (ui_element, updater, force_synchronous);
});
}
} else {
if (ui_element.IsDisposed)
throw new ObjectDisposedException ("Control is already disposed.");
updater ();
}
}
示例14: BeginInvoke
public static void BeginInvoke(this Control c, MethodInvoker code)
{
//c.BeginInvoke(code);
if (c.InvokeRequired)
c.BeginInvoke(code);
else
c.Invoke(code);
}
示例15: BeginInvokeIfRequired
public static void BeginInvokeIfRequired(this Control control, MethodInvoker action)
{
if (control.InvokeRequired) {
control.BeginInvoke(action);
} else {
action();
}
}