他们只是昨天在PDC上谈论了这一点!
.NET中的Await与Tasks(并行编程)结合使用。.NET的下一版本中引入了该关键字。它或多或少使您可以“暂停”方法的执行以等待Task完成执行。这是一个简单的示例:
//create and run a new task Task<DataTable> dataTask = new Task<DataTable>(SomeCrazyDatabaseOperation);//run some other pre immediately after this task is started and running ShowLoaderControl(); StartStoryboard();//this will actually "pause" the pre execution until the task completes. It doesn't lock the thread, but rather waits for the result, similar to an async callback // please so also note, that the task needs to be started before it can be awaited. Otherwise it will never returndataTask.Start();DataTable table = await dataTask;//Now we can perform operations on the Task result, as if we're executing pre after the async operation completed listBoxControl.DataContext = table; StopStoryboard(); HideLoaderControl();
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)