Task.Run and UI Progress Updates

前端 未结 3 1219
耶瑟儿~
耶瑟儿~ 2020-12-01 14:12

This code snippet is from Stephen Cleary\'s blog and gives an example of how to report progress when using Task.Run. I would like to know why there are no cross thread issue

3条回答
  •  一生所求
    2020-12-01 14:49

    Progress catches the current SynchronisationContext when it is instantiated. Whenever you call Report, it secretly delegates that to the captured context. In the example, the captured context is the UI, meaning that no exceptions occur.

提交回复
热议问题