Get the dispatcher before the Task.
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Threading;
|
||||
@@ -23,22 +24,22 @@ namespace WpfViewModelFirst
|
||||
{
|
||||
CurrentViewModel = null;
|
||||
CurrentViewModel = new Part1ViewModel(Part1Action);
|
||||
// MainFrameViewModel = new Part2ViewModel();
|
||||
// MainFrameViewModel = new Part2ViewModel();
|
||||
}
|
||||
private void Part1Action()
|
||||
{
|
||||
var currentDispatcher = Dispatcher.CurrentDispatcher;
|
||||
CurrentViewModel = null;
|
||||
Task delay = Task.Run(LongDelay).ContinueWith(c =>
|
||||
Task delay = Task<string>.Run(LongDelay).ContinueWith(c =>
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(c.Result);
|
||||
CurrentViewModel = new Part2ViewModel();
|
||||
Strings.Add($"{DateTime.Now}");
|
||||
currentDispatcher.Invoke(() =>
|
||||
{
|
||||
Strings.Add($"{DateTime.Now}");
|
||||
}
|
||||
);
|
||||
}, TaskContinuationOptions.OnlyOnRanToCompletion);
|
||||
//Task.Run(async () => await LongDelay()).ContinueWith(c =>
|
||||
// {
|
||||
// System.Diagnostics.Debug.WriteLine(c.Result);
|
||||
//CurrentViewModel = new Part2ViewModel();
|
||||
//}, TaskContinuationOptions.OnlyOnRanToCompletion);
|
||||
}
|
||||
|
||||
private async Task<string> LongDelay()
|
||||
|
||||
Reference in New Issue
Block a user