新的C#等待功能有什么作用?[关闭]

新的C#等待功能有什么作用?[关闭],第1张

新的C#等待功能有什么作用?[关闭]

他们只是昨天在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();


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5559764.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-14
下一篇 2022-12-14

发表评论

登录后才能评论

评论列表(0条)

保存