本文整理汇总了C#中System.Windows.Forms.Control.EndInvoke方法的典型用法代码示例。如果您正苦于以下问题:C# Control.EndInvoke方法的具体用法?C# Control.EndInvoke怎么用?C# Control.EndInvoke使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.Control
的用法示例。
在下文中一共展示了Control.EndInvoke方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnDecryptionError
/// <summary>
/// Shows standard decryption error UI within the context of a parent form
/// </summary>
public static DecryptionErrorAction OnDecryptionError(Control form, IContentEncryption encryptor)
{
if (form.InvokeRequired)
{
DecryptionErrorAction result = DecryptionErrorAction.Skip;
IAsyncResult async = form.BeginInvoke(new MethodInvoker(delegate
{
result = ShowDecryptionErrorDialog(form, encryptor);
}));
form.EndInvoke(async);
return result;
}
return ShowDecryptionErrorDialog(form, encryptor);
}
示例2: GetPassword
/// <summary>
/// Shows standard content encryption UI
/// </summary>
public static DecryptResult GetPassword(Control form, string attachmentName, string passwordName, string passwordDescription, out string password)
{
if (form.InvokeRequired)
{
DecryptResult result = DecryptResult.Ok;
string pwd = string.Empty;
IAsyncResult async = form.BeginInvoke(new MethodInvoker(delegate
{
result = ShowPasswordRequestDialog(form, attachmentName, passwordName, passwordDescription, out pwd);
}));
form.EndInvoke(async);
password = pwd;
return result;
}
return ShowPasswordRequestDialog(form, attachmentName, passwordName, passwordDescription, out password);
}
示例3: GetPasswords
/// <summary>
/// Shows standard content encryption UI
/// </summary>
public static DecryptResult GetPasswords(Control form, string attachmentName, string attachmentDisplayName, out string openPassword, out string modifyPassword)
{
if (form.InvokeRequired)
{
DecryptResult result = DecryptResult.Ok;
string pwdOpen = string.Empty;
string pwdModify = string.Empty;
IAsyncResult async = form.BeginInvoke(new MethodInvoker(delegate
{
result = ShowExtendedPasswordRequestDialog(form, attachmentName, attachmentDisplayName, out pwdOpen, out pwdModify);
}));
form.EndInvoke(async);
openPassword = pwdOpen;
modifyPassword = pwdModify;
return result;
}
return ShowExtendedPasswordRequestDialog(form, attachmentName, attachmentDisplayName, out openPassword, out modifyPassword);
}
示例4: CrossThreadInvoke
/// <summary>
/// Attempts to execute the specified action on the thread that owns the specified control, if the control is in a valid state.
/// </summary>
/// <param name="control">The control in whose thread context the specified action should be executed.</param>
/// <param name="action">The action to execute on the owning thread of the specified control. The action is invoked across threads.
/// </param>
/// <returns>A value indicating whether the action was executed. If the control has been disposed at the time the action is ready
/// to execute then it will not execute and the return value is false; otherwise, it is true.</returns>
private static bool CrossThreadInvoke(Control control, Action action)
{
// On entering this method, we know implicitly the control has a valid window handle and a cross-thread call is required.
IAsyncResult asyncResult;
bool invoked = false;
try
{
// We use BeginInvoke so we can get access to the wait handle being used. The normal Invoke also uses a wait handle whilst
// it waits for the message to be processed but fails to release it, requiring that the handle be finalized. We'll step in
// and release it deterministically.
// The use of the MethodInvoker delegate here is intentional. The internal mechanism that process invoked calls will
// attempt to cast to this delegate (and several others) and invoke them directly which is faster than having to invoke a
// dynamic delegate. Despite having the same signature, an Action delegate cannot be cast to the MethodInvoker delegate.
asyncResult = control.BeginInvoke(new MethodInvoker(() =>
{
// It is possible our request was posted, but that a message earlier in the queue destroys the control. Our request
// will still be processed but the control will no longer be valid so we will not attempt to run the specified actions.
if (control.IsDisposed)
return;
// The control is still valid and since we are on the UI thread, we can now safely run the actions without fear of
// disposal.
invoked = true;
action();
}));
}
catch (InvalidOperationException)
{
// If a window handle no longer exists, the control was disposed before we could make our call to BeginInvoke.
return false;
}
try
{
// We need to wait on the completion of our action so our method completes synchronously.
control.EndInvoke(asyncResult);
}
catch (ObjectDisposedException)
{
// The control can be disposed before we are able to wait on the result. We can ignore this as we have our flag to see if
// the action was executed.
}
// Release the wait handle so it does not have to be finalized.
asyncResult.AsyncWaitHandle.Dispose();
// If we get this far, we know our wrapper method was executed but we need to use this flag in case we bailed from executing
// the specified actions because the control was disposed by the time our wrapper came to execute.
return invoked;
}
示例5: InvokeException1
public void InvokeException1 () {
Control c = new Control ();
IAsyncResult result;
result = c.BeginInvoke (new TestDelegate (delegate_call));
c.EndInvoke (result);
}
示例6: EndAndDisposeAsyncResult
/// <summary>
/// Calls EndInvoke on <paramref name="asyncResult"/> and disposes of the wait handle.
/// </summary>
/// <param name="control">The control to invoke upon.</param>
/// <param name="asyncResult">The async result on which to await a result.</param>
private static void EndAndDisposeAsyncResult(Control control, IAsyncResult asyncResult)
{
try
{
control.EndInvoke(asyncResult);
}
finally
{
asyncResult.AsyncWaitHandle.Dispose();
}
}
示例7: SafeInvoke
/// <summary>
/// .net2.0中线程安全访问控件扩展方法,可以获取返回值,可能还有其它问题
/// </summary>
/// CrossThreadCalls.SafeInvoke(this.statusStrip1, new CrossThreadCalls.TaskDelegate(delegate()
/// {
/// tssStatus.Text = "开始任务...";
/// }));
/// CrossThreadCalls.SafeInvoke(this.rtxtChat, new CrossThreadCalls.TaskDelegate(delegate()
/// {
/// rtxtChat.AppendText("测试中");
/// }));
/// 参考:http://wenku.baidu.com/view/f0b3ac4733687e21af45a9f9.html
/// <summary>
public static void SafeInvoke(Control control, TaskDelegate handler)
{
if (control.InvokeRequired)
{
while (!control.IsHandleCreated)
{
if (control.Disposing || control.IsDisposed)
return;
}
IAsyncResult result = control.BeginInvoke(new InvokeMethodDelegate(SafeInvoke), new object[] { control, handler });
control.EndInvoke(result);//获取委托执行结果的返回值
return;
}
IAsyncResult result2 = control.BeginInvoke(handler);
control.EndInvoke(result2);
}