This is not Task Chaining.
You need to do Task chaining using ContinueWith
. Last task would need to update the UI.
Task.Factory.StartNew( () => DoThis())
.ContinueWith((t1) => DoThat())
.ContinueWith((t2) => UpdateUi(),
TaskScheduler.FromCurrentSynchronizationContext());
Note the last line has TaskScheduler.FromCurrentSynchronizationContext()
this will ensure task will run in the synchronization context (UI Thread).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…