相关疑难解决方法(0)

是否适合扩展Control以提供始终如一的安全Invoke/BeginInvoke功能?

在我维护一个严重违反winforms中的跨线程更新规则的旧应用程序的过程中,我创建了以下扩展方法,以便在我发现它们时快速修复非法调用:

/// <summary>
/// Execute a method on the control's owning thread.
/// </summary>
/// <param name="uiElement">The control that is being updated.</param>
/// <param name="updater">The method that updates uiElement.</param>
/// <param name="forceSynchronous">True to force synchronous execution of 
/// updater.  False to allow asynchronous execution if the call is marshalled
/// from a non-GUI thread.  If the method is called on the GUI thread,
/// execution is always synchronous.</param>
public static void SafeInvoke(this Control uiElement, Action updater, bool forceSynchronous)
{
    if …
Run Code Online (Sandbox Code Playgroud)

c# extension-methods controls invoke winforms

33
推荐指数
2
解决办法
8592
查看次数

标签 统计

c# ×1

controls ×1

extension-methods ×1

invoke ×1

winforms ×1