I am using a third-party library. That library contains an object with an async
method that returns Task<SomeStuff>
. I am wrapping that object and others into my own class. My wrapper method is also async
and has the same return. Calling the wrapper method works fine in my unit tests and a console app. However, it doesn't work in my WPF GUI app. I have tried different methods for invoking in my GUI but nothing works.
In my unit tests, I invoke with GetAwaiter().GetResult()
. However, in my GUI this never returns.
I tried using Start()
but that results in an error: "Start may not be called on a promise-style task."
What do I need to do to make this work in my GUI?
// Foo() returns Task<SomeStuff>
// this works fine in unit test as well as console app, but not in GUI (WPF)
SomeStuff stuff = myWrapper.Foo().GetAwaiter().GetResult();
// this results in error: "Start may not be called on a promise-style task."
Task<SomeStuff> myTask = myWrapper.Foo();
myTask.Start();
myTask.Wait();