in visual studio 2012 .NET 4.5 i have this
public async void Execute(object parameter)
{
task = action(parameter);
OnCanExecuteChanged();
await _task;
OnCanExecuteChanged();
}
can i have the same exact behavior in .NET 4.0 Visual studio 2010 without async and await and without hanging the UI?
Yes, you can use this code:
//To invoke the OnCanExecuteChanged in same thread that the Execute method
var scheduler = TaskScheduler.FromCurrentSynchronizationContext();
_task.ContinueWith(t => OnCanExecuteChanged(), scheduler);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.