I am trying to set the apartment state on a task but see no option in doing this. Is there a way to do this using a Task?
for (int i = 0; i < zom.Count; i
This is what I'm using with Action since I don't need to return anything:
public static class TaskUtil
{
public static Task StartSTATask(Action action)
{
var tcs = new TaskCompletionSource
Where I call it like this:
TaskUtil.StartSTATask(async () => await RefreshRecords());
For details, please see https://github.com/xunit/xunit/issues/103 and Func vs. Action vs. Predicate
FYI, this is the exception I was getting where I needed to set the apartment state:
System.InvalidOperationException occurred HResult=-2146233079
Message=The calling thread must be STA, because many UI components require this. Source=PresentationCore StackTrace: at System.Windows.Input.InputManager..ctor() at System.Windows.Input.InputManager.GetCurrentInputManagerImpl() at System.Windows.Input.Keyboard.ClearFocus()