首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >扩展方法问题

扩展方法问题
EN

Stack Overflow用户
提问于 2010-12-22 01:57:45
回答 1查看 132关注 0票数 1

为什么下面的代码(.NET-4,扩展方法)不让我使用Application.DoEvents();

代码语言:javascript
复制
/// <summary>
/// Invokes in the Dispatcher an empty action.
/// An thread safe equivalent of the ancient Application.DoEvents.
/// </summary>
public static void DoEvents(this Application a)
{
    Application.Current.Dispatcher.Invoke(
        System.Windows.Threading.DispatcherPriority.Background,
        new Action(delegate { })); 
}

编辑

SLaks备注后的更新版本

代码语言:javascript
复制
    public static void DoEvents(this Application a)
    {
        if (a != null)
        {
            a.Dispatcher.Invoke(
                System.Windows.Threading.DispatcherPriority.Background,
                new Action(delegate { }));
        }
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-12-22 01:58:45

您只能在实例中调用扩展方法。

因此,由于这是一个Application实例,因此您将能够编写Application.Current.DoEvents()

但是,不能在类型本身上调用它。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4502372

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档