private async Task PerformDataAnalysisAsync() { // At this point, we’re on whatever thread the caller was on (UI thread or background). // The first thing we do is call a VS service, so ensure we’re on the UI thread. await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); this.solution.EnumProjects(…); await DoSomethingAsync(); // We’re still on the UI thread at this point. // Let’s get off to do some expensive work without disturbing the user. await TaskScheduler.Default; ExpensiveCalculation(); await SaveWorkToDiskAsync(); // Still on a threadpool thread. }