【问题标题】:C# .net 4.5 code to .net 4.0C# .net 4.5 代码到 .net 4.0
【发布时间】:2013-12-15 06:38:15
【问题描述】:

在 Visual Studio 2012 .NET 4.5 我有这个

 public async void Execute(object parameter)
    {
      task = action(parameter);
      OnCanExecuteChanged();
      await _task;
      OnCanExecuteChanged();
    }

我可以在 .NET 4.0 Visual Studio 2010 中获得相同的行为,而无需异步和等待且无需挂起 UI?

【问题讨论】:

标签: c# visual-studio-2010 c#-4.0


【解决方案1】:

是的,您可以使用此代码:

//To invoke the OnCanExecuteChanged in same thread that the Execute method
var scheduler = TaskScheduler.FromCurrentSynchronizationContext();
_task.ContinueWith(t => OnCanExecuteChanged(), scheduler);

【讨论】:

    猜你喜欢
    • 2013-09-14
    • 1970-01-01
    • 2013-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-25
    • 2012-10-12
    相关资源
    最近更新 更多