为什么下面的代码(.NET-4,扩展方法)不让我使用Application.DoEvents();
/// <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备注后的更新版本
public static void DoEvents(this Application a)
{
if (a != null)
{
a.Dispatcher.Invoke(
System.Windows.Threading.DispatcherPriority.Background,
new Action(delegate { }));
}
}发布于 2010-12-22 01:58:45
您只能在实例中调用扩展方法。
因此,由于这是一个Application实例,因此您将能够编写Application.Current.DoEvents()。
但是,不能在类型本身上调用它。
https://stackoverflow.com/questions/4502372
复制相似问题