WPF C# Task run method System.InvalidOperationException: 'The calling thread must be STA, because many UI components require this.'
Task.Run(() => { InitData(); }); The calling thread must be STA, because many UI components require this.
The solution is make sure current method in current main thread
Application.Current.Dispatcher.BeginInvoke(new Action(() => { InitData(); }));